Boost logo

Boost :

From: Michael Marcin (mike_at_[hidden])
Date: 2007-01-24 11:39:02


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk