[Dune] [Dune-Commit] dune-common r5882 - trunk/dune/common
Carsten Gräser
graeser at math.fu-berlin.de
Wed Feb 3 18:12:49 CET 2010
Hi Oliver,
> How about the following compromise: We add a new allocator
> static_allocator to dune-common. This allocator would be standard-
> compliant, similar to array_allocator, but actually contain the
> memory it manages. You could then write something like (not tested)
>
> typedef Dune::static_allocator<int,10> MyAllocator;
> MyAllocator allocator;
> std::{vector|set|map|whatever}<int,MyAllocator>(allocator);
but list/set/map might (and will in general) allocate
mulitple independent memory fractions. So you can not
use the static_allocator despite you know that the container
will allocate a fixed number (of unknown size) at once.
So one will hardly use this with anything else then vector.
>
> This is bit simpler than the gnu array_allocator. You could then
> implement ReservedVector using this allocator, much like Carsten
> suggested. This would be a very short file, then.
That would be much nicer, however you still waste
memory with the 'pointer to storage' and 'capacity'
members of std::vector.
Regards
Carsten
>
> Yrs,
> Oliver
>
>
>> 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
>>
>
>
--
----------------------------------------------------------------------
Carsten Gräser | phone: +49-30 / 838-75349
Freie Universität Berlin | fax : +49-30 / 838-54977
Institut für Mathematik | email: graeser at math.fu-berlin.de
Arnimallee 6 |
14195 Berlin, Germany | URL : http://page.mi.fu-berlin.de/graeser
----------------------------------------------------------------------
More information about the Dune
mailing list