apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Striker <stri...@apache.org>
Subject RE: Pools, C++, and Exceptions Best Practices
Date Thu, 14 Oct 2004 10:32:30 GMT
On Thu, 2004-10-14 at 08:08, David Barrett wrote:
> > -----Original Message-----
> > From: Sander Striker [mailto:striker@apache.org]
> > Subject: Re: Pools, C++, and Exceptions Best Practices
> > 
> > You'll be eating through your available memory at a pretty quick rate
> > this way.  Each pool preallocates 8k.  In your case this means that
> > every object you instantiate, you allocate 8k.
> 
> Does APR allocate 8k per root memory pool, or for subpool?

Per pool, be it a root pool or a subpool.

> When I destroy a subpool does it recycle the memory?

Yes.

> So, for example, how much memory (roughly) would the following code
> allocate:
> 
> # apr_pool_t *root, *sub0, *sub1;
> # apr_pool_create( &root, 0 );
> # apr_pool_create( &sub0, root );
> # apr_pool_destroy( sub0 );
> # apr_pool_create( &sub1, root );

16k.

> Basically, does a pool grow infinitely until it's destroyed, or does it
> recycle subpool memory?

When a pool is cleared all of it's allocated memory except an 8k block
is returned to the pools allocator.  When a pool is destroyed, that
final 8k block is also returned to the allocator.  All pools sharing
an allocator recycle memory that the allocator retains.
The amount of memory the allocator retains can be influenced using
apr_allocator_max_free_set().

In case you are wondering what I am babbling about allocators:
APR creates an allocator at initialization, which is the allocator used
by the internal root pool.  A pool created with a NULL parent will be a
child of the internal root pool and therefor inherit its allocator.

HTH,

Sander

Mime
View raw message