Why is the boost::fast_pool_allocator built on top of a singleton pool, and not a separate pool per allocator instance? Or to put it another way, why only provide that, and not the option of having a pool per allocator? Would having that be a bad idea?
I have a class that internally uses about 10 different boost::unordered_map types. If I’d used the std::allocator then all the memory would go back to the system when it called delete, whereas now I have to call release_memory on many different allocator types at some point.
Would I be stupid to roll my own allocator that uses pool instead of singleton_pool?
thanks
It’s difficult for an allocator to have state, since all instances of an allocator had to be ‘equivalent’ to be used by the standard library (at least portably).
From 20.1.5/4 “Allocator requirements”:
It then goes on to say:
So an implementation can be written to allow non-equivalent allocator instances, but then your allocator is dependent in implementation-defined behavior.
See this other SO answer for some additional details (and it looks like I need to tend to some promised updating of that answer…)