Loading...
Searching...
No Matches
Memory Pool Functions
Apache Portability Runtime library
Collaboration diagram for Memory Pool Functions:

## Modules

| Pool Cleanup Functions
| Pool Debugging functions

## Macros

#define | APR_POOL_DECLARE_ACCESSOR(type)
#define | APR_POOL_IMPLEMENT_ACCESSOR(type)
#define | APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)

## Typedefs

typedef struct apr_pool_t | apr_pool_t
typedef int(* | apr_abortfunc_t) (int retcode)

## Functions

apr_status_t | apr_pool_initialize (void)
void | apr_pool_terminate (void)
apr_status_t | apr_pool_create_ex (apr_pool_t **newpool, apr_pool_t *parent, apr_abortfunc_t abort_fn, apr_allocator_t *allocator)
apr_status_t | apr_pool_create_core_ex (apr_pool_t **newpool, apr_abortfunc_t abort_fn, apr_allocator_t *allocator)
apr_status_t | apr_pool_create_unmanaged_ex (apr_pool_t **newpool, apr_abortfunc_t abort_fn, apr_allocator_t *allocator)
apr_status_t | apr_pool_create_ex_debug (apr_pool_t **newpool, apr_pool_t *parent, apr_abortfunc_t abort_fn, apr_allocator_t *allocator, const char *file_line)
apr_status_t | apr_pool_create_core_ex_debug (apr_pool_t **newpool, apr_abortfunc_t abort_fn, apr_allocator_t *allocator, const char *file_line)
apr_status_t | apr_pool_create_unmanaged_ex_debug (apr_pool_t **newpool, apr_abortfunc_t abort_fn, apr_allocator_t *allocator, const char *file_line)
apr_status_t | apr_pool_create (apr_pool_t **newpool, apr_pool_t *parent)
apr_status_t | apr_pool_create_core (apr_pool_t **newpool)
apr_status_t | apr_pool_create_unmanaged (apr_pool_t **newpool)
apr_allocator_t * | apr_pool_allocator_get (apr_pool_t *pool)
void | apr_pool_clear (apr_pool_t *p)
void | apr_pool_clear_debug (apr_pool_t *p, const char *file_line)
void | apr_pool_destroy (apr_pool_t *p)
void | apr_pool_destroy_debug (apr_pool_t *p, const char *file_line)
void * | apr_palloc (apr_pool_t *p, apr_size_t size)
void * | apr_palloc_debug (apr_pool_t *p, apr_size_t size, const char *file_line)
void * | apr_pcalloc (apr_pool_t *p, apr_size_t size)
void * | apr_pcalloc_debug (apr_pool_t *p, apr_size_t size, const char *file_line)
void | apr_pool_abort_set (apr_abortfunc_t abortfunc, apr_pool_t *pool)
apr_abortfunc_t | apr_pool_abort_get (apr_pool_t *pool)
apr_pool_t * | apr_pool_parent_get (apr_pool_t *pool)
int | apr_pool_is_ancestor (apr_pool_t *a, apr_pool_t *b)
void | apr_pool_tag (apr_pool_t *pool, const char *tag)
apr_status_t | apr_pool_userdata_set (const void *data, const char *key, apr_status_t(*cleanup)(void *), apr_pool_t *pool)
apr_status_t | apr_pool_userdata_setn (const void *data, const char *key, apr_status_t(*cleanup)(void *), apr_pool_t *pool)
apr_status_t | apr_pool_userdata_get (void **data, const char *key, apr_pool_t *pool)

## Detailed Description

## Macro Definition Documentation

## APR_POOL__FILE_LINE__

#define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)

Pool debug levels

    | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
    ---------------------------------
    |   |   |   |   |   |   |   | x |  General debug code enabled (useful in
                                       combination with --with-efence).

    |   |   |   |   |   |   | x |   |  Verbose output on stderr (report
                                       CREATE, CLEAR, DESTROY).

    |   |   |   | x |   |   |   |   |  Verbose output on stderr (report
                                       PALLOC, PCALLOC).

    |   |   |   |   |   | x |   |   |  Lifetime checking. On each use of a
                                       pool, check its lifetime.  If the pool
                                       is out of scope, abort().
                                       In combination with the verbose flag
                                       above, it will output LIFE in such an
                                       event prior to aborting.

    |   |   |   |   | x |   |   |   |  Pool owner checking.  On each use of a
                                       pool, check if the current thread is the
                                       pool's owner.  If not, abort().  In
                                       combination with the verbose flag above,
                                       it will output OWNER in such an event
                                       prior to aborting.  Use the debug
                                       function apr_pool_owner_set() to switch
                                       a pool's ownership.

    When no debug level was specified, assume general debug mode.
    If level 0 was specified, debugging is switched off.

the place in the code where the particular function was called

## APR_POOL_DECLARE_ACCESSOR

#define APR_POOL_DECLARE_ACCESSOR | ( |  | type | ) |

Value:
APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
(const apr_##type##_t *the##type)
APR_DECLARE
#define APR_DECLARE(type)
Definition apr.h:507
apr_pool_t
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60

Declaration helper macro to construct apr_foo_pool_get()s.

This standardized macro is used by opaque (APR) data types to return the apr_pool_t that is associated with the data type.

APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the accessor function. A typical usage and result would be:

       APR_POOL_DECLARE_ACCESSOR(file);
    becomes:
       APR_DECLARE(apr_pool_t *) apr_file_pool_get(const apr_file_t *thefile);

Remarks
  Doxygen unwraps this macro (via doxygen.conf) to provide actual help for each specific occurrence of apr_foo_pool_get.
  the linkage is specified for APR. It would be possible to expand the macros to support other linkages.

## APR_POOL_IMPLEMENT_ACCESSOR

#define APR_POOL_IMPLEMENT_ACCESSOR | ( |  | type | ) |

Value:
APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
(const apr_##type##_t *the##type) \
{ return the##type->pool; }

Implementation helper macro to provide apr_foo_pool_get()s.

In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to actually define the function. It assumes the field is named "pool".

## Typedef Documentation

## apr_abortfunc_t

typedef int(* apr_abortfunc_t) (int retcode)

A function that is called when allocation fails.

## apr_pool_t

typedef struct apr_pool_t apr_pool_t

The fundamental pool type

## Function Documentation

## apr_palloc()

void * apr_palloc | ( | apr_pool_t * | p,
|  | apr_size_t | size
| ) |  |

Allocate a block of memory from a pool

Parameters

  p | The pool to allocate from
  size | The amount of memory to allocate

Returns
  The allocated memory

## apr_palloc_debug()

void * apr_palloc_debug | ( | apr_pool_t * | p,
|  | apr_size_t | size,
|  | const char * | file_line
| ) |  |

Debug version of apr_palloc

Parameters

  p | See: apr_palloc
  size | See: apr_palloc
  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Returns
  See: apr_palloc

## apr_pcalloc()

void * apr_pcalloc | ( | apr_pool_t * | p,
|  | apr_size_t | size
| ) |  |

Allocate a block of memory from a pool and set all of the memory to 0

Parameters

  p | The pool to allocate from
  size | The amount of memory to allocate

Returns
  The allocated memory

## apr_pcalloc_debug()

void * apr_pcalloc_debug | ( | apr_pool_t * | p,
|  | apr_size_t | size,
|  | const char * | file_line
| ) |  |

Debug version of apr_pcalloc

Parameters

  p | See: apr_pcalloc
  size | See: apr_pcalloc
  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Returns
  See: apr_pcalloc

## apr_pool_abort_get()

apr_abortfunc_t apr_pool_abort_get | ( | apr_pool_t * | pool | ) |

Get the abort function associated with the specified pool.

Parameters

  pool | The pool for retrieving the abort function.

Returns
  The abort function for the given pool.

## apr_pool_abort_set()

void apr_pool_abort_set | ( | apr_abortfunc_t | abortfunc,
|  | apr_pool_t * | pool
| ) |  |

Set the function to be called when an allocation failure occurs.

Remarks
  If the program wants APR to exit on a memory allocation error, then this function can be called to set the callback to use (for performing cleanup and then exiting). If this function is not called, then APR will return an error and expect the calling program to deal with the error accordingly.

## apr_pool_allocator_get()

apr_allocator_t * apr_pool_allocator_get | ( | apr_pool_t * | pool | ) |

Find the pool's allocator

Parameters

  pool | The pool to get the allocator from.

## apr_pool_clear()

void apr_pool_clear | ( | apr_pool_t * | p | ) |

Clear all memory in the pool and run all the cleanups. This also destroys all subpools.

Parameters

  p | The pool to clear

Remarks
  This does not actually free the memory, it just allows the pool to re-use this memory for the next allocation.

See also
  apr_pool_destroy()

## apr_pool_clear_debug()

void apr_pool_clear_debug | ( | apr_pool_t * | p,
|  | const char * | file_line
| ) |  |

Debug version of apr_pool_clear.

Parameters

  p | See: apr_pool_clear.
  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Remarks
  Only available when APR_POOL_DEBUG is defined. Call this directly if you have your apr_pool_clear calls in a wrapper function and wish to override the file_line argument to reflect the caller of your wrapper function. If you do not have apr_pool_clear in a wrapper, trust the macro and don't call apr_pool_destroy_clear directly.

## apr_pool_create()

apr_status_t apr_pool_create | ( | apr_pool_t ** | newpool,
|  | apr_pool_t * | parent
| ) |  |

Create a new pool.

Parameters

  newpool | The pool we have just created.
  parent | The parent pool. If this is NULL, the new pool is a root pool. If it is non-NULL, the new pool will inherit all of its parent pool's attributes, except the apr_pool_t will be a sub-pool.

Remarks
  This function is thread-safe, in the sense that multiple threads can safely create subpools of the same parent pool concurrently. Similarly, a subpool can be created by one thread at the same time that another thread accesses the parent pool.

## apr_pool_create_core()

apr_status_t apr_pool_create_core | ( | apr_pool_t ** | newpool | ) |

Create a new unmanaged pool.

Parameters

  newpool | The pool we have just created.

## apr_pool_create_core_ex()

apr_status_t apr_pool_create_core_ex | ( | apr_pool_t ** | newpool,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator
| ) |  |

Create a new pool.

Deprecated:

See also
  apr_pool_create_unmanaged_ex.

## apr_pool_create_core_ex_debug()

apr_status_t apr_pool_create_core_ex_debug | ( | apr_pool_t ** | newpool,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator,
|  | const char * | file_line
| ) |  |

Debug version of apr_pool_create_core_ex.

Deprecated:

See also
  apr_pool_create_unmanaged_ex_debug.

## apr_pool_create_ex()

apr_status_t apr_pool_create_ex | ( | apr_pool_t ** | newpool,
|  | apr_pool_t * | parent,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator
| ) |  |

Create a new pool.

Parameters

  newpool | The pool we have just created.
  parent | The parent pool. If this is NULL, the new pool is a root pool. If it is non-NULL, the new pool will inherit all of its parent pool's attributes, except the apr_pool_t will be a sub-pool.
  abort_fn | A function to use if the pool cannot allocate more memory.
  allocator | The allocator to use with the new pool. If NULL the allocator of the parent pool will be used.

Remarks
  This function is thread-safe, in the sense that multiple threads can safely create subpools of the same parent pool concurrently. Similarly, a subpool can be created by one thread at the same time that another thread accesses the parent pool.

## apr_pool_create_ex_debug()

apr_status_t apr_pool_create_ex_debug | ( | apr_pool_t ** | newpool,
|  | apr_pool_t * | parent,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator,
|  | const char * | file_line
| ) |  |

Debug version of apr_pool_create_ex.

Parameters

  newpool |

See also
  apr_pool_create.

Parameters

  parent |

See also
  apr_pool_create.

Parameters

  abort_fn |

See also
  apr_pool_create.

Parameters

  allocator |

See also
  apr_pool_create.

Parameters

  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Remarks
  Only available when APR_POOL_DEBUG is defined. Call this directly if you have your apr_pool_create_ex calls in a wrapper function and wish to override the file_line argument to reflect the caller of your wrapper function. If you do not have apr_pool_create_ex in a wrapper, trust the macro and don't call apr_pool_create_ex_debug directly.

## apr_pool_create_unmanaged_ex()

apr_status_t apr_pool_create_unmanaged_ex | ( | apr_pool_t ** | newpool,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator
| ) |  |

Create a new unmanaged pool.

Parameters

  newpool | The pool we have just created.
  abort_fn | A function to use if the pool cannot allocate more memory.
  allocator | The allocator to use with the new pool. If NULL a new allocator will be created with the new pool as owner.

Remarks
  An unmanaged pool is a special pool without a parent; it will NOT be destroyed upon apr_terminate. It must be explicitly destroyed by calling apr_pool_destroy, to prevent memory leaks. Use of this function is discouraged, think twice about whether you really really need it.

Warning
  Any child cleanups registered against the new pool, or against sub-pools thereof, will not be executed during an invocation of apr_proc_create(), so resources created in an "unmanaged" pool hierarchy will leak to child processes.

## apr_pool_create_unmanaged_ex_debug()

apr_status_t apr_pool_create_unmanaged_ex_debug | ( | apr_pool_t ** | newpool,
|  | apr_abortfunc_t | abort_fn,
|  | apr_allocator_t * | allocator,
|  | const char * | file_line
| ) |  |

Debug version of apr_pool_create_unmanaged_ex.

Parameters

  newpool |

See also
  apr_pool_create_unmanaged.

Parameters

  abort_fn |

See also
  apr_pool_create_unmanaged.

Parameters

  allocator |

See also
  apr_pool_create_unmanaged.

Parameters

  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Remarks
  Only available when APR_POOL_DEBUG is defined. Call this directly if you have your apr_pool_create_unmanaged_ex calls in a wrapper function and wish to override the file_line argument to reflect the caller of your wrapper function. If you do not have apr_pool_create_core_ex in a wrapper, trust the macro and don't call apr_pool_create_core_ex_debug directly.

## apr_pool_destroy()

void apr_pool_destroy | ( | apr_pool_t * | p | ) |

Destroy the pool. This takes similar action as apr_pool_clear() and then frees all the memory.

Parameters

  p | The pool to destroy

Remarks
  This will actually free the memory

## apr_pool_destroy_debug()

void apr_pool_destroy_debug | ( | apr_pool_t * | p,
|  | const char * | file_line
| ) |  |

Debug version of apr_pool_destroy.

Parameters

  p | See: apr_pool_destroy.
  file_line | Where the function is called from. This is usually APR_POOL__FILE_LINE__.

Remarks
  Only available when APR_POOL_DEBUG is defined. Call this directly if you have your apr_pool_destroy calls in a wrapper function and wish to override the file_line argument to reflect the caller of your wrapper function. If you do not have apr_pool_destroy in a wrapper, trust the macro and don't call apr_pool_destroy_debug directly.

## apr_pool_initialize()

apr_status_t apr_pool_initialize | ( | void |  | ) |

Setup all of the internal structures required to use pools

Remarks
  Programs do NOT need to call this directly. APR will call this automatically from apr_initialize.

## apr_pool_is_ancestor()

int apr_pool_is_ancestor | ( | apr_pool_t * | a,
|  | apr_pool_t * | b
| ) |  |

Determine if pool a is an ancestor of pool b.

Parameters

  a | The pool to search
  b | The pool to search for

Returns
  True if a is an ancestor of b, NULL is considered an ancestor of all pools.

Remarks
  if compiled with APR_POOL_DEBUG, this function will also return true if A is a pool which has been guaranteed by the caller (using apr_pool_join) to have a lifetime at least as long as some ancestor of pool B.

## apr_pool_parent_get()

apr_pool_t * apr_pool_parent_get | ( | apr_pool_t * | pool | ) |

Get the parent pool of the specified pool.

Parameters

  pool | The pool for retrieving the parent pool.

Returns
  The parent of the given pool.

## apr_pool_tag()

void apr_pool_tag | ( | apr_pool_t * | pool,
|  | const char * | tag
| ) |  |

Tag a pool (give it a name)

Parameters

  pool | The pool to tag
  tag | The tag

## apr_pool_terminate()

void apr_pool_terminate | ( | void |  | ) |

Tear down all of the internal structures required to use pools

Remarks
  Programs do NOT need to call this directly. APR will call this automatically from apr_terminate.

## apr_pool_userdata_get()

apr_status_t apr_pool_userdata_get | ( | void ** | data,
|  | const char * | key,
|  | apr_pool_t * | pool
| ) |  |

Return the data associated with the current pool.

Parameters

  data | The user data associated with the pool.
  key | The key for the data to retrieve
  pool | The current pool.

## apr_pool_userdata_set()

apr_status_t apr_pool_userdata_set | ( | const void * | data,
|  | const char * | key,
|  | apr_status_t(*)(void *) | cleanup,
|  | apr_pool_t * | pool
| ) |  |

Set the data associated with the current pool

Parameters

  data | The user data associated with the pool.
  key | The key to use for association
  cleanup | The cleanup program to use to cleanup the data (NULL if none)
  pool | The current pool

Warning
  The data to be attached to the pool should have a life span at least as long as the pool it is being attached to.

Users of APR must take EXTREME care when choosing a key to use for their data. It is possible to accidentally overwrite data by choosing a key that another part of the program is using. Therefore it is advised that steps are taken to ensure that unique keys are used for all of the userdata objects in a particular pool (the same key in two different pools or a pool and one of its subpools is okay) at all times. Careful namespace prefixing of key names is a typical way to help ensure this uniqueness.

## apr_pool_userdata_setn()

apr_status_t apr_pool_userdata_setn | ( | const void * | data,
|  | const char * | key,
|  | apr_status_t(*)(void *) | cleanup,
|  | apr_pool_t * | pool
| ) |  |

Set the data associated with the current pool

Parameters

  data | The user data associated with the pool.
  key | The key to use for association
  cleanup | The cleanup program to use to cleanup the data (NULL if none)
  pool | The current pool

Note
  same as apr_pool_userdata_set(), except that this version doesn't make a copy of the key (this function is useful, for example, when the key is a string literal)

Warning
  This should NOT be used if the key could change addresses by any means between the apr_pool_userdata_setn() call and a subsequent apr_pool_userdata_get() on that key, such as if a static string is used as a userdata key in a DSO and the DSO could be unloaded and reloaded between the _setn() and the _get(). You MUST use apr_pool_userdata_set() in such cases.
  More generally, the key and the data to be attached to the pool should have a life span at least as long as the pool itself.