ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | 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...
 

Typedefs

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

Functions

CxMempoolcxMempoolCreate (size_t capacity, cx_destructor_func destr)
 Creates an array-based memory pool with a shared destructor function.
 
static CxMempoolcxBasicMempoolCreate (size_t capacity)
 Creates a basic array-based memory pool.
 
void cxMempoolDestroy (CxMempool *pool)
 Destroys a memory pool and frees the managed memory.
 
void cxMempoolSetDestructor (void *memory, cx_destructor_func fnc)
 Sets 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
Version
3.0

Function Documentation

◆ cxBasicMempoolCreate()

static CxMempool * cxBasicMempoolCreate ( size_t  capacity)
inlinestatic

Creates a basic array-based memory pool.

Parameters
capacitythe initial capacity of the pool
Returns
the created memory pool or NULL if allocation failed

◆ 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
destrthe destructor function to use for allocated memory
Returns
the created memory pool or NULL if allocation failed

◆ cxMempoolDestroy()

void cxMempoolDestroy ( CxMempool pool)

Destroys a memory pool and frees the managed memory.

Parameters
poolthe memory pool to destroy

◆ 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 allocated in the pool
destrthe destructor function
Returns
zero on success, non-zero on failure

◆ 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