Hi,
is there a way to access pool::get_next_size, pool::set_next_size from my
own fast_pool_allocator without modifying the boost source (1.33.1).
This my_fast_pool_allocator is a copy of fast_pool_allocator that tries to
allocate the requested memory with next_size divided by 2 if malloc returns
NULL.
I added static member functions get_next_size/set_next_size to singleton_pool
which works, but is there a way without modifying the boost source.
If not, would it make sense to add these two methods in a future boost release.
This is the allocate method of my_fast_pool_alloctor:
template
class my_fast_pool_allocator
{
...
static pointer allocate(const size_type n)
{
typedef boost::singleton_pool mypool;
pointer ret = NULL;
for( ; !ret; )
{
if (n == 1 )
{
ret = static_cast<pointer>( mypool::malloc() );
}
else
{
ret = static_cast<pointer>( mypool::ordered_malloc(n) );
}
size_t nsize = mypool::get_next_size();
if( !ret ) // not enough memory available
{
if( nsize <= n ) // even less than we really need
break;
nsize >>= 1; // request half the size
nsize = std::max( nsize, n ); // at least as much as we really need
}
mypool::set_next_size(nsize);
}
if (ret == 0)
throw std::bad_alloc();
return ret;
}
...
};
Regards,
Stefan