Boost logo

Boost Users :

Subject: Re: [Boost-users] custom allocators, pool_alloc release_memory() seems to be broken
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-03-18 10:14:30


AMDG

B Hart wrote:
> I tried contacting Stephen the pool_allocator author, but his e-mail
> is invalid (shouldn't the docs be updated?)
>
> Here is what I wrote in case someone else here can offer some help:
>
> I'm trying unsuccessfully to use your Boost::pool_alloc. In the
> documentation at the boost website:
> http://www.boost.org/doc/libs/1_42_0/libs/pool/doc/interfaces.html
> it says:
>
> // 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
>
> release_memory() does not seem to work. Not sure why. I called a
> function in my code to verify my processes memory usage, and see that
> indeed memory was not being released. I also google searched and
> found that others experienced the same:
>

The problem is not release_memory per se. The problem
is the interaction between singleton_pool, pool_allocator
and std::set. The example is using vector, which (probably)
allocates exactly the type that you give it. std::set is allocating
a different type. pool_allocator uses multiple singleton_pools,
one for each size of object. release_memory would work if
you could find the size of the object that std::set is actually allocating.
Without knowing that, the best you can do is something like

// assume that the sizes are multiples of 4 bytes.
boost::singleton_pool<boost::pool_allocator_tag, 4>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 8>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 12>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 16>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 20>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 24>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 28>::release_memory();
boost::singleton_pool<boost::pool_allocator_tag, 32>::release_memory();
// hope that's enough...

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net