[Dune] allocators... dingleton vs. instance
Carsten Gräser
graeser at math.fu-berlin.de
Wed Oct 3 20:44:31 CEST 2012
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.
Best,
Carsten
In fact
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);
>
> Is this supposed to work? In general I would assume not (although it
> will work for many implementations). Is there somewhere a place that
> states that the instance of an allocator is important and not only the
> type?
>
> Christian
More information about the Dune
mailing list