~tester() { #ifdef VERBOSE std::cout << this << ": tester::~tester()" << std::endl; #endif mem.check_out(this); }
void test_alloc() { { // Allocate several tester objects. Delete one. std::vector<tester, boost::pool_allocator<tester> > l; for(int i=0; i < 10; ++i) { l.push_back(tester()); } l.pop_back(); } { // Allocate several tester objects. Delete two. std::deque<tester, boost::pool_allocator<tester> > l; for(int i=0; i < 10; ++i) { l.push_back(tester()); } l.pop_back(); l.pop_front(); } { // Allocate several tester objects. Delete two. std::list<tester, boost::fast_pool_allocator<tester> > l; // lists rebind their allocators, so dumping is useless for(int i=0; i < 10; ++i) { l.push_back(tester()); } l.pop_back(); l.pop_front(); } tester * tmp; { // Create a memory leak on purpose. (Allocator doesn't have // garbage collection) // (Note: memory leak) boost::pool_allocator<tester> a; tmp = a.allocate(1, 0); new (tmp) tester(); } if(mem.ok()) { BOOST_ERROR("Pool allocator cleaned up itself"); } // Remove memory checker entry (to avoid error later) and // clean up memory leak tmp->~tester(); boost::pool_allocator<tester>::deallocate(tmp, 1); // test allocating zero elements { boost::pool_allocator<tester> alloc; tester* ip = alloc.allocate(0); alloc.deallocate(ip, 0); } }
tester(bool throw_except = false) { if(throw_except) { throw std::logic_error("Deliberate constructor exception"); } mem.check_in(this); }
~tester() { mem.check_out(this); }
tester(const tester &) { mem.check_in(this); }