Boost.Pool: Writing a base class for per-class pool allocation

Hi all, I am currently trying to write a base class which overloads new and delete so that they allocate from a boost pool: template<typename T> class pool_object { public: static void* operator new(size_t) { return pool_.malloc(); } static void operator delete(void *p) { pool_.free(p); } private: static boost::pool<> pool_; }; template<typename T> boost::pool<> pool_object<T>::pool_(sizeof(T)); The idea is that one can write: class foo : public pool_object<foo> { ... }; The problem with this is that boost::pool is not thread-safe. The thread-safe variant is a singleton pool. However, this is parametrized by a size: boost::singleton_pool<sizeof(T)> -- which is a problem as T is incomplete. Are there any solutions other than sticking my own mutex into the class? Regards, Freddie.
participants (1)
-
Freddie Witherden