Does anybody know of an STL implementation that allows for dynamic allocators to be passed in to an instance of a container before use.
The scenario is that we have a general memory allocator that manages a number of pools of memory and for each instance of say stl::vector we want to allocate each instance from a different pool of memory.
The problem with the standard STL implementations is that you can only define the memory pool on a type basis ie all vector's of type int would allocate from the same pool.
I've already swapped out our default stl::allocator for one that has a state ie the pool we want to allocate this instance from but this doesn't work well for say stl::list where it allocates things in the default ctor.
For reasons related to our library we also don't have a valid pool in the ctor for all objects and so we want to call a 'set memory pool' function before users can use the stl container.
Has anybody come across an implementation that supports this kind of thing?
The typed allocator can use a general allocator underneath to perform the allocations.
Allocator needs to support these functions:
Assuming you have a mechanism that just allocates memory and deallocates memory, you can use that to implement some of the functions above.
The advantage of allocators being typed is that you know you are going to create lots of items of exactly the same size and can therefore create your "pages" to fit. The biggest issue can be that you are forced by allocate() to return contiguous buffers (and indeed vector needs them).
http://www.cplusplus.com/reference/std/memory/allocator/
Your question is still a bit unclear as to why this is not sufficient. You can initialise the memory-pool with "once" logic. (If it is multi-threaded you can use boost::once to achieve this).