newbie: help to start with object_pool

Hi this is my first try with boost. I need an object pool, where I can preallocate X objects and reuse them with ability to allocate more if the pool runs empty and shrink my pool if needed. My questions: 1. Is object_pool suitable for this purpose? 2. Does object_pool.free() returns object memory to the pool or return pool's memory to the system? 3. How do I use object_pool.construct()? I didn't get the number of parameters requirement in the documentation (http://www.boost.org/doc/libs/1_40_0/libs/pool/doc/interfaces/object_pool.ht...)

1. Is object_pool suitable for this purpose? I guess, yes
2. Does object_pool.free() returns object memory to the pool or return pool's memory to the system? I guess, it will reuse memory, but will not return it to system unless purge() method is called or the pool is destroyed. At least this is my experience while working with pool and object_pool.
3. How do I use object_pool.construct()? I didn't get the number of parameters requirement in the documentation You provided link that says about: "t.construct(???) - ElementType must have a constructor matching ???; the number of parameters given must not exceed what is supported through pool_construct" - so it seems to be ready for any constructor params.
Hope this helps. If you will do tests then note, that on non-fragmented memory using object_pool->construct vs new/delete may give similar results. When object pool is useful - when you work with fragmented memory.
participants (2)
-
Jenia
-
Roman Shmelev