Dear list,

 

I’m using boost::fast_pool_allocator to replace the default allocator in a map.  This works great, but I’m having a bit of trouble freeing the memory explicitly. 

 

I’d like to call boost::singleton_pool::purge_memory(), but I don’t know how to instantiate the correct version.  Is there a way to determine the size of the chunks the map allocator will require?  I have determined by debugging that the size is 28 bytes, but I imagine that this is dependent on the particular implementation of map. 

 

Below is a sample program which illustrates the situation.  Any guidance would be very appreciated.

 

- Finley

 

///////////////////////////////////////////////////////////////////////////

 

#include <assert.h>

#include <iso646.h>

 

#include <map>

#include <boost\pool\pool_alloc.hpp>

 

class mydata

{

public:

   mydata() {}

 

   mydata( int _a, short _bchar _c ) :

      a(_a), b(_b), c(_c) {}

 

   int a ;

   short b ;

   char c ;

};

 

typedef std::map< int, mydata,

                  std::less<int>,

                  boost::fast_pool_allocator< std::pair<int, mydata> > > mymap ;

 

int _tmain(int argc, _TCHAR* argv[])

{

   {

      mymap m ;

 

      for ( int i = 0 ; i < 10000 ; i++ )

         m[i] = mydata( i, i, i ) ;

   }

 

   bool memory_freed = boost::singleton_pool< boost::fast_pool_allocator_tag, sizeof( std::pair<int,mydata> ) >::purge_memory() ;

   //bool memory_freed = boost::singleton_pool< boost::fast_pool_allocator_tag, 28 >::purge_memory() ;

   assert( memory_freed ) ;

 

      return 0;

}