xmempool 1.1.2
A memory pool implemented by C.
Loading...
Searching...
No Matches
xmempool.h File Reference

A memory pool implemented by C. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define XMEMPOOL_VERSION_MAJOR   1
 Major version number of xmempool.
 
#define XMEMPOOL_VERSION_MINOR   1
 Minor version number of xmempool.
 
#define XMEMPOOL_VERSION_PATCH   2
 Patch version number of xmempool.
 
#define XMEMPOOL_VERSION_STRING   "1.1.2"
 Version string of xmempool.
 

Typedefs

typedef char * xmem_pool_handle
 Handle type for memory pools.
 

Functions

xmem_pool_handle xmem_create_pool (uint32_t block_size)
 Create a new memory pool.
 
void xmem_destroy_pool (xmem_pool_handle pool)
 Destroy a memory pool and free all associated resources.
 
char * xmem_alloc (xmem_pool_handle handle)
 Allocate a block from the memory pool.
 
int xmem_free (xmem_pool_handle handle, char *pointer)
 Free a block back to the memory pool.
 
void xmem_print_info (xmem_pool_handle pool)
 Print information about the memory pool.
 
void xmem_clean_up ()
 Clean up global resources used by xmempool.
 

Detailed Description

A memory pool implemented by C.

Warning
THREAD SAFETY NOTICE: Individual pools are not thread-safe. For multi-threaded use, create separate pools for each thread.

Definition in file xmempool.h.

Macro Definition Documentation

◆ XMEMPOOL_VERSION_MAJOR

#define XMEMPOOL_VERSION_MAJOR   1

Major version number of xmempool.

Definition at line 26 of file xmempool.h.

◆ XMEMPOOL_VERSION_MINOR

#define XMEMPOOL_VERSION_MINOR   1

Minor version number of xmempool.

Definition at line 31 of file xmempool.h.

◆ XMEMPOOL_VERSION_PATCH

#define XMEMPOOL_VERSION_PATCH   2

Patch version number of xmempool.

Definition at line 36 of file xmempool.h.

◆ XMEMPOOL_VERSION_STRING

#define XMEMPOOL_VERSION_STRING   "1.1.2"

Version string of xmempool.

Definition at line 41 of file xmempool.h.

Typedef Documentation

◆ xmem_pool_handle

typedef char* xmem_pool_handle

Handle type for memory pools.

This is a pointer to the first pool in the chain of memory pools. It's used as an opaque handle to interact with the memory pool system.

Definition at line 49 of file xmempool.h.

Function Documentation

◆ xmem_alloc()

char * xmem_alloc ( xmem_pool_handle handle)
extern

Allocate a block from the memory pool.

This function returns a pointer to a free block from the pool. If the current pool is full, it automatically creates and chains a new pool. The allocated block is always zero-initialized.

Parameters
handleHandle to the pool to allocate from
Returns
Pointer to the allocated block, or NULL if allocation failed

◆ xmem_clean_up()

void xmem_clean_up ( )
extern

Clean up global resources used by xmempool.

This function frees all global resources used by the xmempool system, particularly the memory used for managing block nodes. It should be called when the xmempool system is no longer needed.

◆ xmem_create_pool()

xmem_pool_handle xmem_create_pool ( uint32_t block_size)
extern

Create a new memory pool.

This function creates the initial memory pool with the specified block size. It allocates a large chunk of memory and divides it into fixed-size blocks. Additional pools will be created automatically as needed.

Parameters
block_sizeSize of each block in the pool
Returns
Handle to the created pool, or NULL if creation failed

◆ xmem_destroy_pool()

void xmem_destroy_pool ( xmem_pool_handle pool)
extern

Destroy a memory pool and free all associated resources.

This function frees all memory associated with the pool, including all chained pools and their blocks. It also recovers all block nodes used for managing free blocks.

Parameters
poolHandle to the pool to be destroyed

◆ xmem_free()

int xmem_free ( xmem_pool_handle handle,
char * pointer )
extern

Free a block back to the memory pool.

This function returns a block to the free list of the first pool in the chain. It does not actually free memory, but makes the block available for future allocations.

Parameters
handleHandle to the pool
pointerPointer to the block to be freed
Returns
1 if successful, 0 if failed (e.g., if no free block nodes are available)

◆ xmem_print_info()

void xmem_print_info ( xmem_pool_handle pool)
extern

Print information about the memory pool.

This function prints detailed information about each pool in the chain, including its size, block count, memory range, and number of free blocks.

Parameters
poolHandle to the pool