Skip to content

Instantly share code, notes, and snippets.

@rowanj
Created June 27, 2012 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanj/3004102 to your computer and use it in GitHub Desktop.
Save rowanj/3004102 to your computer and use it in GitHub Desktop.
Using a single Boost.Pool with a class heirarchy
struct Base{virtual ~Base(){}; int x;};
struct Derived : public Base {int y;};
#import <boost/pool/pool_alloc.hpp>
template <typename T>
T* construct()
{
T* result = reinterpret_cast<T*>(boost::pool_allocator<Base>::pool_allocator::allocate(sizeof (T)));
new (result) T();
return result;
}
int main()
{
Base* b = construct<Base>();
Base* d = construct<Derived>();
Derived* d_ = dynamic_cast<Derived*>(d);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment