I would like to take advantage of the following feature advertised boost::fast_pool_allocator(see the Boost documentation for the Boost Pool ):
For example, you may have a situation where you want to select a bunch of small objects at one point, and then reach a point in yours where none of them are needed anymore. Using the pool interfaces, you can choose to run your destructors or simply remove them into oblivion ...
(see here for this quote.)
The key phrase throws them into oblivion . I do not want destructors to call these objects.
(The reason is that I have millions of tiny objects that make up the extremely complex ownership network on the heap, and it takes about 20 minutes for my program to call all destructors when an object with one parent object goes off the stack. I don't need these destructors because there are no desired side effects and all memory is contained in boost::pool.)
Unfortunately, despite the promise of the above documentation and the promise of the concept boost::pool, I cannot find a way to prevent managed object destructors from being called.
The task is easily isolated in a small sample program:
class Obj
{
public:
~Obj()
{
int m = 0;
}
};
typedef std::map<int, Obj, std::less<int>,
boost::fast_pool_allocator<std::pair<int const, Obj>>>
fast_int_to_int_map;
class Foo
{
public:
~Foo()
{
}
fast_int_to_int_map mmap;
};
void mfoo()
{
Foo foo;
foo.mmap[0] = Obj();
foo.mmap[1] = Obj();
}
int main()
{
mfoo();
boost::singleton_pool<boost::fast_pool_allocator_tag,
sizeof(std::pair<int const, Obj>)>::purge_memory();
}
As noted in the code comments, instance destructors Objthat are managed boost::poolare always invoked.
, Boost Pool, drop them off into oblivion, ?