[Dune] [Dune-Commit] dune-common r5882 - trunk/dune/common
Christian Engwer
christi at uni-hd.de
Tue Feb 2 22:03:48 CET 2010
Hi Oliver,
> I object to this class. ReservedVector is nothing else than a std::vector
> with an array_allocator. We would have more flexibility and standard
> conformance if we added such an allocator to dune-common instead
> of a new container class. Therefore I would like to ask you to consider
> removing ReservedVector again and implementing an array_allocator
> instead.
I just checked the array_alloctor and it does something completely
different. It allows you to reuse memory from a preallocated array. I
need something that behaves like a std::array.
Consider the code below. It will not work. And despite the fact that
the two approaches do something different, I don't think that it is
easier to maintain some code copied from the gcc, that this rather
simple well documented file.
You might say that we could still write some other kind of allocator,
but I really have no idea, how this allocator should work.
Christian
Example:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/common/fvector.hh>
#include <dune/common/exceptions.hh>
#include <iostream>
#include <vector>
#include <ext/array_allocator.h>
#include <dune/common/reservedvector.hh>
int main()
{
Dune::ReservedVector<int,2> foo[2];
typedef __gnu_cxx::array_allocator<int> alloc;
std::vector<int,alloc> foo2[2];
char * oldptr = 0;
char * oldptr2 = 0;
for (int i=0; i<2; i++)
for (int j=0; j<2; j++)
{
std::cout << &(foo[i][j]) << "\t";
std::cout << ((char*)&(foo[i][j]))-oldptr << "\t";
std::cout << &(foo2[i][j]) << "\t";
std::cout << ((char*)&(foo2[i][j]))-oldptr2 << std::endl;
oldptr = (char*)&(foo[i][j]);
oldptr2 = (char*)&(foo2[i][j]);
}
return 0;
}
More information about the Dune
mailing list