You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by David Barrett <db...@quinthar.com> on 2004/10/08 05:56:27 UTC

Pools, C++, and Exceptions Best Practices

Is anyone in the audience using apr pools in a C++ application?  Can you
point to any sample code showing how to override 'new' and 'delete' (or
manually invoke constructors and destructors) to manage objects within a
pool?

Right now I have an ugly mix of pools for apr objects and heap for C++
objects, and I'd prefer to use apr pools exclusively.  I'm thinking pools
might complement structured exception handling very well: create a sub-pool
before each 'try' block, and destroy it in the 'catch' block if an exception
is thrown.  In theory, this would ensure that whatever data allocated up to
the point the exception was thrown would be safely cleaned up.

Alternatively, do you have any suggestions on how best to use pools with
C++?  Currently I'm just creating a pool for each object in its constructor,
and destroying it in the destructor.  Am I on the right track?

-david