I am looking to implement a (doubly) linked list which only calls placement new
internally, directing all memory to a pool allocated with something like:
char *memPool = new char[4096]; // One-off normal 'new'
Initially I was going to implement my own class which takes a pointer to a (class managing a) pre-allocated memory pool. However I want to be sure first that I can't achieve the same outcome with std::list
. In particular, the third section of David Rodríguez's answer to this SO question worries me.
It makes sense that std::list
will have to call new
and delete
on its component nodes, but I want to modify this behaviour so that all the nodes to be allocated with placement new
into my custom pool. Therefore my question is:
Is there a way to specify that a placement new
std::list
such as:
std::list<std::shared_ptr<Cls>> myList = new (pool.getFreeAddr()) list<Cls>;
should also allocate its nodes using a custom allocator, so that everything is stored strictly inside my own memory pool?
(Note: I am aware of the need to use custom allocation/deletion functions with the shared_ptrs
if I want them in the custom memory pool too.)