Dave Abrahams wrote:
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]
 


Well, how do you suppose to handle variable arguments here ? I believe placement new
is the only right solution. It also allows for important generalization - then the pool
allocation manage only allocation itself, not initialization. More good news : SGI STL/STLport
already use that generalized pool allocator ;). And, you may just use allocator<T> w/o
redefined placement new or delete.
 
 

 
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.
 
Yep, and it's trivial for pool allocator<>, as those issues are decoupled then.
 
 
 
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

------------------------------------------------------------------------
Learn more with SmartPlanet. It's a new way of learning online.
SmartPlanet offers hundreds of courses to take on your time,
in your space. Join for FREE today!
http://click.egroups.com/1/1704/1/_/9351/_/951715483/

-- Create a poll/survey for your group!
-- http://www.egroups.com/vote?listname=boost&m=1