Should I ever prevent memory leaks using shared pointers with boost::object_pool (in case of an exception inside malloc-destroy block)?
If yes, what is the correct way to initialize shared_ptr?
How to clean up memory afterwards?
#include <boost/pool/object_pool.hpp> #include <boost/shared_ptr.hpp> int main() { boost::object_pool<int> pool; // Which is the correct way of initializing the shared pointer: // 1) int *i = pool.malloc(); boost::shared_ptr<int> sh(i); int *j = pool.construct(2); boost::shared_ptr<int> sh2(j); // or 2) boost::shared_ptr<int> sh(pool.malloc()); // Now, how should i clean up the memory? // without shared_ptr I'd call here pool.destroy(i) and pool.destroy(j) }