fast_pool_allocator question

Hi: I try fast_pool_allocator and it does not release memory. See the following program Any ideas? Thanks! -Kawasaki --- Begin --- #include <vector> #include <boost/pool/pool_alloc.hpp> #include <list> using namespace std; using namespace boost; #include "memusage.cpp" //-------------------------------------------------- void func() { list<int, fast_pool_allocator<int> > v; // list<int> v; for (int i = 0; i < 1000000; ++i) { v.push_back(i); } printf("2. MEM USAGE = %d\n", getMemUsage()); } //-------------------------------------------------- int main(int argc, char **argv) { printf("1. MEM USAGE = %d\n", getMemUsage()); func(); func(); func(); /// 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 printf("3. MEM USAGE = %d\n", getMemUsage()); boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(int)>::release_memory(); printf("4. MEM USAGE = %d\n", getMemUsage()); return 1; } --- END output 1. MEM USAGE = 11 MB 2. MEM USAGE = 35 2. MEM USAGE = 35 2. MEM USAGE = 35 3. MEM USAGE = 35 4. MEM USAGE = 35 // after release_memory() is called,

On Tue, Oct 7, 2008 at 12:58 AM, Ta-Cheng Lin <tclin1998@gmail.com> wrote:
Hi:
I try fast_pool_allocator and it does not release memory. See the following program Any ideas?
<snip code> Well, this issue has come up before. I can tell you the reason, but I can't remember the solution. The reason is that the singleton instance you are calling release_memory() on is not the singleton the list is using to allocate nodes. Remember that std::list<int> will rebind the allocator to allocate SomeNodeStruct<int> instead of plain ints. As far as I know, there is not a portable way to get the type of "SomeNodeStruct". HTH, --Michael Fawcett
participants (2)
-
Michael Fawcett
-
Ta-Cheng Lin