
24 Jan
2007
24 Jan
'07
10:01 p.m.
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