Custom (pool) allocator with boost shared_ptr
I want objects managed by a shared_ptr to be allocated from a pool, say Boost's Pool interface, how can this be achieved? Here's the code to do what you want (probably won't compile as I don't have boost on hand and I'm writing it from memory): class YourClass; // your data type, defined somewhere else boost::object_pool<YourClass> allocator; void destroy(YourClass* pointer) { allocator.destroy(pointer); } boost::shared_ptr<YourClass> create() { // usage of object_pool<??>::construct requires that you have a // YourClass::YourClass(void) defined. If you need to pass arguments // to the new