![]() |
ucx
UAP Common Extensions
|
Interface for memory pool implementations. More...
Go to the source code of this file.
Data Structures | |
| struct | cx_mempool_memory_s |
| A memory block in a simple memory pool. More... | |
| struct | cx_mempool_memory2_s |
| A memory block in an advanced memory pool. More... | |
| struct | cx_mempool_foreign_memory_s |
| Represents memory that is not allocated by, but registered with a pool. More... | |
| struct | cx_mempool_s |
| The basic structure of a memory pool. More... | |
Macros | |
| #define | cxMempoolCreateSimple(capacity) |
| Creates a basic array-based memory pool. | |
| #define | cxMempoolCreateAdvanced(capacity) |
| Creates a basic array-based memory pool. | |
| #define | cxMempoolCreatePure(capacity) |
| Creates a basic array-based memory pool. | |
Typedefs | |
| typedef struct cx_mempool_s | CxMempool |
| Common type for all memory pool implementations. | |
Enumerations | |
| enum | cx_mempool_type { CX_MEMPOOL_TYPE_SIMPLE , CX_MEMPOOL_TYPE_ADVANCED , CX_MEMPOOL_TYPE_PURE } |
| Specifies how individual blocks are allocated. More... | |
Functions | |
| void | cxMempoolFree (CxMempool *pool) |
| Deallocates a memory pool and frees the managed memory. | |
| CxMempool * | cxMempoolCreate (size_t capacity, enum cx_mempool_type type) |
| Creates an array-based memory pool. | |
| void | cxMempoolGlobalDestructor (CxMempool *pool, cx_destructor_func fnc) |
| Sets the global destructor for all memory blocks within the specified pool. | |
| void | cxMempoolGlobalDestructor2 (CxMempool *pool, cx_destructor_func2 fnc, void *data) |
| Sets the global destructor for all memory blocks within the specified pool. | |
| void | cxMempoolSetDestructor (void *memory, cx_destructor_func fnc) |
| Sets the destructor function for a specific allocated memory object. | |
| void | cxMempoolSetDestructor2 (void *memory, cx_destructor_func2 fnc, void *data) |
| Sets the destructor function for a specific allocated memory object. | |
| void | cxMempoolRemoveDestructor (void *memory) |
| Removes the destructor function for a specific allocated memory object. | |
| void | cxMempoolRemoveDestructor2 (void *memory) |
| Removes the destructor function for a specific allocated memory object. | |
| int | cxMempoolRegister (CxMempool *pool, void *memory, cx_destructor_func destr) |
| Registers foreign memory with this pool. | |
| int | cxMempoolRegister2 (CxMempool *pool, void *memory, cx_destructor_func2 destr, void *data) |
| Registers foreign memory with this pool. | |
| int | cxMempoolTransfer (CxMempool *source, CxMempool *dest) |
| Transfers all the memory managed by one pool to another. | |
| int | cxMempoolTransferObject (CxMempool *source, CxMempool *dest, const void *obj) |
| Transfers an object from one pool to another. | |
Interface for memory pool implementations.
| #define cxMempoolCreateAdvanced | ( | capacity | ) |
Creates a basic array-based memory pool.
Convenience macro to create a memory pool of type CX_MEMPOOL_TYPE_ADVANCED.
| capacity | (size_t) the initial capacity of the pool |
CxMempool*) the created memory pool or NULL if allocation failed | #define cxMempoolCreatePure | ( | capacity | ) |
Creates a basic array-based memory pool.
Convenience macro to create a memory pool of type CX_MEMPOOL_TYPE_PURE.
| capacity | (size_t) the initial capacity of the pool |
CxMempool*) the created memory pool or NULL if allocation failed | #define cxMempoolCreateSimple | ( | capacity | ) |
Creates a basic array-based memory pool.
Convenience macro to create a memory pool of type CX_MEMPOOL_TYPE_SIMPLE.
| capacity | (size_t) the initial capacity of the pool |
CxMempool*) the created memory pool or NULL if allocation failed | enum cx_mempool_type |
Specifies how individual blocks are allocated.
| Enumerator | |
|---|---|
| CX_MEMPOOL_TYPE_SIMPLE | Allows registration of cx_destructor_func for each memory block. |
| CX_MEMPOOL_TYPE_ADVANCED | Allows registration of cx_destructor_func2 for each memory block. |
| CX_MEMPOOL_TYPE_PURE | No individual destructor registration allowed. In this mode, no additional memory per block is allocated. |
| CxMempool * cxMempoolCreate | ( | size_t | capacity, |
| enum cx_mempool_type | type ) |
Creates an array-based memory pool.
The type determines how much additional memory is allocated per block to register a destructor function.
| capacity | the initial capacity of the pool (an implementation default if zero) |
| type | the type of memory pool |
NULL if allocation failed | void cxMempoolFree | ( | CxMempool * | pool | ) |
Deallocates a memory pool and frees the managed memory.
| pool | the memory pool to free |
| void cxMempoolGlobalDestructor | ( | CxMempool * | pool, |
| cx_destructor_func | fnc ) |
Sets the global destructor for all memory blocks within the specified pool.
| pool | the memory pool |
| fnc | the destructor that shall be applied to all memory blocks |
| void cxMempoolGlobalDestructor2 | ( | CxMempool * | pool, |
| cx_destructor_func2 | fnc, | ||
| void * | data ) |
Sets the global destructor for all memory blocks within the specified pool.
| pool | the memory pool |
| fnc | the destructor that shall be applied to all memory blocks |
| data | additional data for the destructor function |
| int cxMempoolRegister | ( | CxMempool * | pool, |
| void * | memory, | ||
| cx_destructor_func | destr ) |
Registers foreign memory with this pool.
The destructor, in contrast to memory allocated by the pool, MUST free the memory. This function can be used with any pool of any type, since destructors for registered memory are entirely independent of the pool's memory management.
The destructor for the registered memory will be called after all pooled items have been freed.
| pool | the pool |
| memory | the object to register (MUST NOT be already allocated in the pool) |
| destr | the destructor function |
| zero | success |
| non-zero | failure |
| int cxMempoolRegister2 | ( | CxMempool * | pool, |
| void * | memory, | ||
| cx_destructor_func2 | destr, | ||
| void * | data ) |
Registers foreign memory with this pool.
The destructor, in contrast to memory allocated by the pool, MUST free the memory. This function can be used with any pool of any type, since destructors for registered memory are entirely independent of the pool's memory management.
The destructor for the registered memory will be called after all pooled items have been freed.
NULL. If you wish to register a destructor without additional data, use cxMempoolRegister().| pool | the pool |
| memory | the object to register (MUST NOT be already allocated in the pool) |
| destr | the destructor function |
| data | additional data for the destructor function |
| zero | success |
| non-zero | failure |
| void cxMempoolRemoveDestructor | ( | void * | memory | ) |
Removes the destructor function for a specific allocated memory object.
If the type of memory pool is not CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. If the memory is not managed by a UCX memory pool, the behavior is undefined.
| memory | the object allocated in the pool |
| void cxMempoolRemoveDestructor2 | ( | void * | memory | ) |
Removes the destructor function for a specific allocated memory object.
If the type of memory pool is not CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. If the memory is not managed by a UCX memory pool, the behavior is undefined.
| memory | the object allocated in the pool |
| void cxMempoolSetDestructor | ( | void * | memory, |
| cx_destructor_func | fnc ) |
Sets the destructor function for a specific allocated memory object.
If the type of memory pool is not CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. If the memory is not managed by a UCX memory pool, the behavior is undefined. The destructor MUST NOT free the memory.
| memory | the object allocated in the pool |
| fnc | the destructor function |
| void cxMempoolSetDestructor2 | ( | void * | memory, |
| cx_destructor_func2 | fnc, | ||
| void * | data ) |
Sets the destructor function for a specific allocated memory object.
If the type of memory pool is not CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. If the memory is not managed by a UCX memory pool, the behavior is undefined. The destructor MUST NOT free the memory.
| memory | the object allocated in the pool |
| fnc | the destructor function |
| data | additional data for the destructor function |
Transfers all the memory managed by one pool to another.
The allocator of the source pool will also be transferred and registered with the destination pool and stays valid, as long as the destination pool is not destroyed.
The source pool will get a completely new allocator and can be reused or destroyed afterward.
This function fails when the destination pool has a different type than the source pool.
| source | the pool to move the memory from |
| dest | the pool where to transfer the memory to |
| zero | success |
| non-zero | allocation failure or incompatible pools |
Transfers an object from one pool to another.
This function fails when the destination pool has a different type than the source pool.
| source | the pool to move the memory from |
| dest | the pool where to transfer the memory to |
| obj | pointer to the object that shall be transferred |
| zero | success |
| non-zero | failure, or the object was not found in the source pool, or the pools are incompatible |