[Dune] [Dune-Commit] dune-common r5882 - trunk/dune/common
Oliver Sander
sander at mi.fu-berlin.de
Wed Feb 3 17:35:57 CET 2010
Hi Christian!
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);
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.
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
>
--
************************************************************************
* Oliver Sander ** email: sander at mi.fu-berlin.de *
* Freie Universität Berlin ** phone: + 49 (30) 838 75348 *
* Institut für Mathematik ** URL : page.mi.fu-berlin.de/~sander *
* Arnimallee 6 ** -------------------------------------*
* 14195 Berlin, Germany ** Member of MATHEON (www.matheon.de) *
************************************************************************
More information about the Dune
mailing list