Boost logo

Boost :

From: Michael Marcin (mike_at_[hidden])
Date: 2007-01-24 17:01:34


gchen wrote:
> <snip>
>
> You are right. Now I remember someone asked why object_pool does not
> have release_memory.
>
> And I have thought about such problem before, maybe a solution is
> to make object_pool dynamic alloced, when we need destroy all objects,
> we can simply delete the object_pool itself. like this:
>
> boost::object_pool<Object> *m_object_pool;
> std::vector<Object*> m_objects;
>
> //
> // create m_object_pool somewhere
> //
>
> ...
>
> // destroy object_pool itself to destroy all objects
> //
> void DestroyAllObjects()
> {
> delete m_object_pool;
> m_objects.clear();
> }
>
> //
> // re-create the object_pool if needed.
> //
>
> Any drawback?
>

Yes, destructing and recreating the object pool will release and
allocate memory with the system heap.

- Michael Marcin


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