[pool] object_pool::destroy_all? (from users)

Michael Marcin wrote:
I started using object_pool recently to solve a problem. I have lots of objects being created and destroyed frequently and stored in a collection. Every so often an event happens which triggers destroying all the objects.
Essentially I have:
boost::object_pool<Object> m_object_pool; std::vector<Object*> m_objects;
Then I have a function
void DestroyAllObjects() { std::vector<Object*>::iterator it, iend = m_objects.end(); for( it = m_objects.begin(); it != iend; ++it ) { m_object_pool.destroy(*it); } m_objects.clear(); }
It seems like there should be a better way of doing this... i.e.
void DestroyAllObjects() { m_object_pool.destroy_all(); m_objects.clear(); }
Also it might be nice to iterate over all the objects in the pool (in which case I wouldn't even need the m_objects vector.
Perhaps there is a better way to solve the problem?
I didn't get an answer on users so I thought I'd ping here. Thanks, Michael Marcin

Michael Marcin wrote:
It seems like there should be a better way of doing this... i.e.
void DestroyAllObjects() { m_object_pool.destroy_all(); m_objects.clear(); }
Also it might be nice to iterate over all the objects in the pool (in which case I wouldn't even need the m_objects vector.
Perhaps there is a better way to solve the problem?
It seems that pool::release_memory or purge_memory can do this. Regards cg
participants (2)
-
gchen
-
Michael Marcin