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

AMDG gchen wrote:
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
1) They don't call the destructors. 2) object_pool does not expose these members. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
gchen wrote:
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
1) They don't call the destructors. 2) object_pool does not expose these members.
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? Regards cg

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
participants (3)
-
gchen
-
Michael Marcin
-
Steven Watanabe