Sturk 1.0.2
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
pool.h File Reference

Memory pool. More...

#include <stddef.h>
Include dependency graph for pool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct StPool StPool
 pool.
 

Functions

StPoolst_pool_create (size_t blk_size)
 Create a pool.
 
void st_pool_destroy (StPool *pool)
 Destroy a pool.
 
void * st_pool_alloc (StPool *pool)
 Allocate a block from a pool.
 
void * st_pool_tryalloc (StPool *pool)
 Try to allocate a block from a pool.
 
void st_pool_free (StPool *pool, void *blk)
 Return a block to a pool.
 

Detailed Description

Memory pool.

Glossary

Term Description
pool fixed-size blocks memory pool

Function Documentation

◆ st_pool_alloc()

void * st_pool_alloc ( StPool pool)

Allocate a block from a pool.

Parameters
[in,out]poolThe pool.

If the pool is empty, allocates a new block from the system memory allocator.

See also
st/os/mem.h
Returns
The block.

◆ st_pool_create()

StPool * st_pool_create ( size_t  blk_size)

Create a pool.

Parameters
[in]blk_sizeThe size of the blocks.
Returns
A new pool.

◆ st_pool_destroy()

void st_pool_destroy ( StPool pool)

Destroy a pool.

Parameters
[in,out]poolThe pool.

◆ st_pool_free()

void st_pool_free ( StPool pool,
void *  blk 
)

Return a block to a pool.

Parameters
[in,out]poolThe pool.
[in,out]blkThe block.

◆ st_pool_tryalloc()

void * st_pool_tryalloc ( StPool pool)

Try to allocate a block from a pool.

Parameters
[in,out]poolThe pool.
Returns
The block, if the pool is not empty. Otherwise, NULL.