Boost logo

Boost Users :

From: Michael Marcin (mike_at_[hidden])
Date: 2007-01-23 16:39:21


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?

Thanks,

Michael Marcin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net