
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 _b, char _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; }

On 4/19/06, Finley Lee <finleyl@alienskin.com> wrote:
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.
Maps have a function for returning copies of their allocators: http://www.roguewave.com/support/docs/sourcepro/edition9/html/stdlibref/map.... HTH, ~ SWMc

On 4/19/06, Finley Lee <finleyl@alienskin.com> wrote:
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 posted about his a few months ago and received no reply. I worked around this issue by not using the singleton allocators, but that's hardly a solution. This seems to be an issue with the rebind. You're really looking for boost::singleton_pool< boost::fast_pool_allocator_tag, sizeof( map node ) >::purge_memory(); but I don't think there is a portable way to determine that map node type or size. Michael Fawcett
participants (3)
-
Finley Lee
-
me22
-
Michael Fawcett