Internal Memory Allocation
Overview
// typedefs typedef struct apr_allocator_t apr_allocator_t; typedef struct apr_memnode_t apr_memnode_t; // structs struct apr_memnode_t; // global functions apr_status_t apr_allocator_create(apr_allocator_t** allocator); void apr_allocator_destroy(apr_allocator_t* allocator); apr_memnode_t* apr_allocator_alloc( apr_allocator_t* allocator, apr_size_t size ); void apr_allocator_free( apr_allocator_t* allocator, apr_memnode_t* memnode ); void apr_allocator_owner_set( apr_allocator_t* allocator, apr_pool_t* pool ); apr_pool_t* apr_allocator_owner_get(apr_allocator_t* allocator); void apr_allocator_max_free_set( apr_allocator_t* allocator, apr_size_t size ); void apr_allocator_mutex_set( apr_allocator_t* allocator, apr_thread_mutex_t* mutex ); apr_thread_mutex_t* apr_allocator_mutex_get(apr_allocator_t* allocator); // macros #define APR_ALLOCATOR_MAX_FREE_UNLIMITED #define APR_MEMNODE_T_SIZE
Detailed Documentation
Typedefs
typedef struct apr_allocator_t apr_allocator_t
the allocator structure
typedef struct apr_memnode_t apr_memnode_t
the structure which holds information about the allocation
Global Functions
apr_status_t apr_allocator_create(apr_allocator_t** allocator)
Create a new allocator
Parameters:
allocator |
The allocator we have just created. |
void apr_allocator_destroy(apr_allocator_t* allocator)
Destroy an allocator Any memnodes not given back to the allocator prior to destroying will not be free()d.
Parameters:
allocator |
The allocator to be destroyed |
apr_memnode_t* apr_allocator_alloc( apr_allocator_t* allocator, apr_size_t size )
Allocate a block of mem from the allocator
Parameters:
allocator |
The allocator to allocate from |
size |
The size of the mem to allocate (excluding the memnode structure) |
void apr_allocator_free( apr_allocator_t* allocator, apr_memnode_t* memnode )
Free a list of blocks of mem, giving them back to the allocator. The list is typically terminated by a memnode with its next field set to NULL.
Parameters:
allocator |
The allocator to give the mem back to |
memnode |
The memory node to return |
void apr_allocator_owner_set( apr_allocator_t* allocator, apr_pool_t* pool )
Set the owner of the allocator Typically pool is the highest level pool using the allocator
Parameters:
allocator |
The allocator to set the owner for |
pool |
The pool that is to own the allocator |
apr_pool_t* apr_allocator_owner_get(apr_allocator_t* allocator)
Get the current owner of the allocator
Parameters:
allocator |
The allocator to get the owner from |
void apr_allocator_max_free_set( apr_allocator_t* allocator, apr_size_t size )
Set the current threshold at which the allocator should start giving blocks back to the system.
Parameters:
allocator |
The allocator to set the threshold on |
size |
The threshold. 0 == unlimited. |
void apr_allocator_mutex_set( apr_allocator_t* allocator, apr_thread_mutex_t* mutex )
Set a mutex for the allocator to use
Parameters:
allocator |
The allocator to set the mutex for |
mutex |
The mutex |
apr_thread_mutex_t* apr_allocator_mutex_get(apr_allocator_t* allocator)
Get the mutex currently set for the allocator
Parameters:
allocator |
The allocator |
Macros
#define APR_ALLOCATOR_MAX_FREE_UNLIMITED
Symbolic constants
#define APR_MEMNODE_T_SIZE
The base size of a memory node - aligned.