[Dune] allocators... dingleton vs. instance
Markus Blatt
markus at dr-blatt.de
Thu Oct 4 10:40:28 CEST 2012
Hi,
On Wed, Oct 03, 2012 at 08:44:31PM +0200, Carsten Gräser wrote:
> Am 02.10.2012 22:32, schrieb Christian Engwer:
> > Dear all,
> >
> > I'm currently puzzled... and I couldn't find an answer in the
> > standard.
> >
> > Assume the following:
> >
> > AllocatorType<Foo> alloc1;
> > AllocatorType<Foo> alloc2;
> > Foo * f = alloc1.allocate(1);
> > alloc2.deallocate(f,1);
>
> Hello Christian,
> the standard (98) does discuss the issue, however in a very
> unsatisfying way:
>
> Section 20.1.5 (Allocator requirements) clause 2 says that two
> allocators compare equal if storage allocated by one can be
> deallocated by the other. But it does _in general_ not require
> that two distinct instances compare equal.
>
> (*) However, clause 4 says that all container classes defined in
> the stl are permitted to additionally require that two instances
> of the same type always compare equal. Then clause 5 imposes
> a very weak restriction to this exception:
>
> Implementors are encouraged to supply libraries that can accept
> allocators that encapsulate more general memory models and
> that support non-equal instances. [...]
>
> In C++11 exception (*) was removed.
>
> Conclusion:
> Standard conforming allocators are not required to support your
> use case. But an allocator that should work with any C++98 stl
> implementation must support it. For C++11 the later is no longer
> the case and so called 'stateful' allocators may become much more
> likely.
Thanks for citing this. I would interpret this even further:
If the two instances of the allocator compare equal, then it is
allowed to deallocate memory allocated from the other
allocator. Otherwise it is a bug in the code.
But that is probably even harder to test?
Cheers,
Markus
--
Do you need more support with DUNE or HPC in general?
Dr. Markus Blatt - HPC-Simulation-Software & Services http://www.dr-blatt.de
Hans-Bunte-Str. 8-10, 69123 Heidelberg, Germany
Tel.: +49 (0) 160 97590858 Fax: +49 (0)322 1108991658
More information about the Dune
mailing list