Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-05-08 08:20:02


On 5/7/07, Michael Gopshtein <mgopshtein_at_[hidden]> wrote:
>
> As a solution I was thinking about adding a "defragment" function to memory
> pool, which will compact it by moving live objects to free cells at the
> "beginning" of the pool. Such feature can be implemented with help of
> additional "index" table of pointers. Of cause, instead of returning pointer
> to allocated object, the pool will return a wrapper object, actually
> pointing to that index table (for which separate "classical" pool can be
> used).
>

Maybe you're looking for the "release_memory" method in the pool
interface. If you're using the pool_allocator as a replacement to the
standard allocators, it might be interesting to note that the
documentation mentions how to use "release_memory":

http://boost.org/libs/pool/doc/interfaces.html

"
pool_alloc

The pool_alloc interface is a Singleton Usage interface with
Exceptions. It is built on the singleton_pool interface, and provides
a Standard Allocator-compliant class (for use in containers, etc.).

Example:

void func()
{
  std::vector<int, boost::pool_allocator<int> > v;
  for (int i = 0; i < 10000; ++i)
    v.push_back(13);
} // Exiting the function does NOT free the system memory allocated by
the pool allocator
  // You must call
  // boost::singleton_pool<boost::pool_allocator_tag,
sizeof(int)>::release_memory()
  // in order to force that
"

Hope this helps.

-- 
Dean Michael C. Berris
http://cplusplus-soup.blogspot.com/
mikhailberis AT gmail DOT com
+63 928 7291459

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