apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garrett Rooney" <roo...@electricjellyfish.net>
Subject Re: utilizing APR in existing c++ app
Date Wed, 22 Mar 2006 07:04:42 GMT
On 3/21/06, Alex.Krumm-Heller@csiro.au <Alex.Krumm-Heller@csiro.au> wrote:
> Hi,
> I was wondering if there was any documentation in terms of strategies
> for utilizing APR in an existing c++ codebase? The main problem I have
> is how to deal with the memory pools that are required for APR
> functions. Is it best to create one giant global pool for the entire
> application and have all APR functions use the global pool, or is it
> better to have a pool exist per object for the lifetime of an object and
> all APR usage within that object utilise its own pool? Any suggestions?

Creating one global pool is fine, but you can't just allocate
everything out of it, you need to use subpool that are scoped
appropriately for whatever you're using them for.  The idea is to
allocate out of a pool that lasts long enough for whatever you're
using, and then to clear that pool when you're done with it.  If you
just allocate out of a large pool you get a giant memory leak.

Making an object carry around a pool isn't especially good either,
since then you have no control over how much gets allocated in its
pool, it's all depending on how many times methods that make use of
the pool get called.

The right way to do it really means passing memory pools around in
code that uses APR, since that code is the only place you have enough
knowledge of object lifetimes to do reasonable pool management.

See http://subversion.tigris.org/hacking.html#apr-pools for a
description of how the Subversion project has decided to use pools,
those guidelines came about after we made most of the mistakes you're
talking about doing, and had to fix things the hard way afterwards.


View raw message