Click to enlarge pool_alloc

Why is boost: fast_pool_allocator built on top of a singleton pool rather than a separate pool per allocator instance? Or, to put it another way, why only provide this, and not the option of having a pool on the allocator? Would that be a bad idea?

I have a class that uses about 10 different types of boost :: unordered_map. If I used std :: allocator, then all the memory would return to the system when it called delete, whereas now I have to call release_memory on many different types of allocators at some point. Will I be silly to steer my allocator that uses a pool instead of singleton_pool?

thanks

+6
c ++ boost singleton pool
source share
1 answer

It is difficult for the dispenser to have state, since all instances of the dispenser must be "equivalent" to be used by the standard library (at least portable).

From 20.1.5 / 4 "Requirements for the counter":

Implementations of the containers described in this International Standard assume that their Allocator template parameter meets the following two additional requirements, other than those listed in Table 32.

  • All instances of this type of dispenser must be interchangeable and always compared with each other.

Followed by:

Developers are encouraged to provide libraries that can accept allocators that encapsulate more general memory models and support unequal instances. In such implementations, any requirements for dispensers with containers that exceed those specified in Table 32, and container semantics and algorithms when dispenser instances are compared with unequal ones, are defined in accordance with the implementation.

In this way, an implementation can be written to allow nonequivalent instances of the dispenser, but then your dispenser depends on the behavior defined by the implementation.

See this other SO answer for more information (and it looks like I need to lean towards some promised update of this answer ...)

+4
source share

All Articles