ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
mempool.h File Reference

Interface for memory pool implementations. More...

#include "common.h"
#include "allocator.h"

Go to the source code of this file.

Data Structures

struct  cx_mempool_s
 The basic structure of a memory pool. More...
 

Macros

#define cxMempoolCreateSimple(capacity)   cxMempoolCreate(capacity, NULL)
 Creates a basic array-based memory pool.
 

Typedefs

typedef struct cx_mempool_s CxMempool
 Common type for all memory pool implementations.
 

Functions

void cxMempoolFree (CxMempool *pool)
 Deallocates a memory pool and frees the managed memory.
 
CxMempoolcxMempoolCreate (size_t capacity, cx_destructor_func destr)
 Creates an array-based memory pool with a shared destructor function.
 
void cxMempoolSetDestructor (void *memory, cx_destructor_func fnc)
 Sets the destructor function for a specific allocated memory object.
 
void cxMempoolRemoveDestructor (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.
 

Detailed Description

Interface for memory pool implementations.

Author
Mike Becker
Olaf Wintermann

Macro Definition Documentation

◆ cxMempoolCreateSimple

#define cxMempoolCreateSimple ( capacity)    cxMempoolCreate(capacity, NULL)

Creates a basic array-based memory pool.

Parameters
capacity(size_t) the initial capacity of the pool
Returns
(CxMempool*) the created memory pool or NULL if allocation failed

Function Documentation

◆ cxMempoolCreate()

CxMempool * cxMempoolCreate ( size_t capacity,
cx_destructor_func destr )

Creates an array-based memory pool with a shared destructor function.

This destructor MUST NOT free the memory.

Parameters
capacitythe initial capacity of the pool
destroptional destructor function to use for allocated memory
Returns
the created memory pool or NULL if allocation failed

◆ cxMempoolFree()

void cxMempoolFree ( CxMempool * pool)

Deallocates a memory pool and frees the managed memory.

Parameters
poolthe memory pool to free

◆ cxMempoolRegister()

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.

A small portion of memory will be allocated to register the information in the pool. If that allocation fails, this function will return non-zero.

Parameters
poolthe pool
memorythe object to register (MUST NOT be already allocated in the pool)
destrthe destructor function
Return values
zerosuccess
non-zerofailure

◆ cxMempoolRemoveDestructor()

void cxMempoolRemoveDestructor ( void * memory)

Removes the destructor function for a specific allocated memory object.

If the memory is not managed by a UCX memory pool, the behavior is undefined. The destructor MUST NOT free the memory.

Parameters
memorythe object allocated in the pool

◆ cxMempoolSetDestructor()

void cxMempoolSetDestructor ( void * memory,
cx_destructor_func fnc )

Sets the destructor function for a specific allocated memory object.

If the memory is not managed by a UCX memory pool, the behavior is undefined. The destructor MUST NOT free the memory.

Parameters
memorythe object allocated in the pool
fncthe destructor function