PoolAllocator is not an allocator
The PoolAllocator
class does not satisfy the allocator requirements of the standard. More specifically the requirements for A
to be an allocator include:
Assume that B
is obtained by rebinding A
to another type and than a
is an object of type A
. Then after constructing a B
using B b(a);
it must hold that A(b) == a
and B(a) == b
. This equality constraint especially implies that you can deallocate memory allocated by another instance that compares equal. Hence all allocators obtained in this way from a single allocator essentially must have shared state.
In contrast, different PoolAllocator
objects will never compare equal, because each one manages its own pool and they never share state. Additionally to not meeting the requirements this also prohibits many use cases. E.g. std::allocate_shared
(creation of shared_ptr
with allocator) will always use a copy of the provided allocator. Thus using a PoolAllocator
many times in std::allocate_shared
will contstruct a new internal pool for any allocation.