Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-02-28 00:21:51


Hi everyone,

I spent a considerable amount of effort recently trying to come up with a
pool allocator for boost, but failed. Here's what I'm trying to accomplish:

A general system for dynamically allocating and constructing instances of a
(possibly non-POD) type. Any outstanding instances in a pool are destroyed
and deallocated when the pool is destroyed.

I'm thinking of usage something like this:

class Foo { ... };
boost::pool<Foo> foo_pool;
Foo *foo1 = foo_pool.create(<args>);
[One could also use placement new above, but it seems harder to control: you
have to force the correct placement delete to be defined, and some compilers
don't support that correctly anyway]

This is harder than it looks - remember that if an exception is thrown
during construction the the memory for the instance should be returned to
the pool *and more importantly* the instance should not be double-destroyed
when the pool is destroyed.

Some of the hard issues are:
1. Memory alignment of instances in the pool
2. You can't make unions of non-POD types, so it's hard to thread a
free-list through memory for instances in the pool

Any suggestions?
Anyone already have a good solution?

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk