$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] fast_pool_allocator question
From: Ta-Cheng Lin (tclin1998_at_[hidden])
Date: 2008-10-06 02:25:28
Hi :
I use  fast_pool_allocator and it seems not
release memory even I explicitly call
 boost::singleton_pool<boost::fast_pool_allocator_tag,
sizeof(int)>::release_memory();
out put
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  <<<--- memory is not released!!!
Any suggestions are welcomed.
-Todd
--- BEGIN ----
#include <boost/pool/pool_alloc.hpp>
#include <list>
using namespace std;
using namespace boost;
#include "memusage.cpp"  <<-- function to call Unix 'top'
//--------------------------------------------------
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;
}
// from boost doc
// If you are seriously concerned about performance,
// use fast_pool_allocator when dealing with containers such as std::list,
// and use pool_allocator when dealing with containers such as std::vector.
-- END --