apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dror Shilo" <Dror.Sh...@ericom.com>
Subject RE: Pools, C++, and Exceptions Best Practices
Date Sun, 10 Oct 2004 08:27:26 GMT
This is a very heavy question!  Creating a pool takes a lot of resources.
If this is a server program that creates a new thread for every new client, you can create
a pool for every thread, but you have to make shore that the lifetime of all your objects
for this client is ended before the thread is dead.
Object that there lifetime are from the beginning until the and of the process has to use
one single pool. 

Object that there lifetime is more the then thread but not forever have to use there on pool.

You have to make deferent constructors for objects that you cannot tell how they will work
(with receiving pool * or generating there pool by them self)

If you will not work on this carefully you will have memory likes or you program will not
be able to handle many clients!

Dror Shilo
Ericom Software

-----Original Message-----
From: David Barrett [mailto:dbarrett@quinthar.com]
Sent: Friday, October 08, 2004 5:56 AM
To: dev@apr.apache.org
Subject: 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

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?


View raw message