You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Andreas Fester <af...@apache.org> on 2006/04/17 12:34:07 UTC
Memory Pool Lifetime
Hi,
I have read http://subversion.tigris.org/hacking.html#apr-pools
and http://www.apachetutor.org/dev/pools, but one question
still remains: when is it safe to destroy memory pools which
are passed to APR functions like apr_sockaddr_info_get() ?
Is it safe to do something like
apr_pool_t *pool;
apr_pool_create(&pool, parentPool);
apr_sockaddr_info_get(..., pool);
apr_pool_destroy(pool);
or are there any performance- or other issues with this
approach?
Thanks & Best Regards,
Andreas
Re: Memory Pool Lifetime
Posted by Max Bowsher <ma...@ukf.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Andreas Fester wrote:
> Hi,
>
>
> I have read http://subversion.tigris.org/hacking.html#apr-pools
> and http://www.apachetutor.org/dev/pools, but one question
> still remains: when is it safe to destroy memory pools which
> are passed to APR functions like apr_sockaddr_info_get() ?
>
> Is it safe to do something like
>
> apr_pool_t *pool;
> apr_pool_create(&pool, parentPool);
> apr_sockaddr_info_get(..., pool);
> apr_pool_destroy(pool);
>
> or are there any performance- or other issues with this
> approach?
The basic rule is simple: Any memory allocated or other APR resources
acquired by a function are bound to the lifetime of the pool supplied to
the function.
So, in your above example, it is invalid to access the apr_sockaddr_t
created by apr_sockaddr_info_get() after you have destroyed 'pool'.
See the documentation of a function for clarifications. For example, in
the case of apr_sockaddr_info_get():
* @param p The pool for the apr_sockaddr_t and associated storage.
If you discover that the pool semantics of any function are inadequately
documented, report that here, and it will be corrected.
Max.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
iD8DBQFEQ3zPfFNSmcDyxYARAseXAJ9s/64U9zgnnkMB7ko8Z/0HeY/nrwCeLOZd
VszDlFR2jP8zKmKjyvZtdGE=
=318Z
-----END PGP SIGNATURE-----