apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bojan Smojver <bo...@rexursive.com>
Subject Re: APR Pools
Date Thu, 02 Nov 2006 02:30:25 GMT
Quoting Ioan Popescu <ipopescu@dataq.com>:

> If they're here to stay, could someone tell me what advantages there are to
> using them instead of malloc()/free()? Regardless of portability.

- well suited for request/response situations (i.e. limited object lifetime)

- faster than many malloc() implementations, especially on pool reuse

- can attach generic cleanup functions to them, with same lifetime

- one cleanup does it all, instead of many free()'s

- can have subpools for allocating memory in a branch of code that may  
end up in an error, in which case the subpool can be easily dumped  
without affecting the parent pool, therefore reducing the memory  

> This is a big problem when you don't know the lifetime of
objects and likely end up using some common pool for them with a very long
lifetime. Any solutions for this?

Apache has a notion of maximum number of requests a child process will  
handle. This can help with memory leaks, as processes simply get  
recycled after a while, therefore freeing any "long lifetime" memory  
that may have leaked in the child during its service period. Not  
suitable for all apps, but may help in some situations.


View raw message