[Dune] [Dune-Commit] dune-common r5882 - trunk/dune/common

Christian Engwer christi at uni-hd.de
Wed Feb 3 09:28:28 CET 2010


Hi Oliver,

> I am afraid I don't really understand what your example code is
> supposed to tell me, but that is probably me and the hour.
> However I guess whatever it does it cannot work because you
> never allocate memory for the array_allocator.  I think you need
> something like
> 
>     typedef __gnu_cxx::array_allocator<int, std::tr1::array<int,2> > 
> MyAllocator;
>     std::tr1::array<int,2> myMemory;   // this is where the actual memory is
>     MyAllocator myAllocator(&myMemory);  // and the allocator takes the 
> memory
>     std::vector<int,MyAllocator> foo3(myAllocator);

As you said, you allocate your memory somewhere else. I want something
with the memory inside. Actually your vector doesn't allocate memory
at all.it is only a view on an other array.

I give you two use cases and perhaps you can tell me how it should
work.

1) write something like this:
   
   std::vector< ReservedVector<int,4> > vec;
   for (int i=0; i<n; i++)
     vec.push_back(ReservedVector<int,4>);

   and assume that the number of elements does vary. How to handle
   dynmic memory memory management with the allocator?

2) you store some stuff in std::vector< ReservedVector<int,4> > and
   hand it to the user. Now the user can delete the vector and the
   memory is freed. How so you handle memory-ownership with the
   allocator?

Perhaps I just don't get it, but I still think that the two approaches
are substatially different.

Christian




More information about the Dune mailing list