Created
June 27, 2012 13:36
-
-
Save rowanj/3004102 to your computer and use it in GitHub Desktop.
Using a single Boost.Pool with a class heirarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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