Lock-free memory pool.
More...
Lock-free memory pool.
The memory pool system provides a lock-free allocator using a pre-allocated array. Its intended to be used for performance-critical structures and as a even more specialized alternative to the Object Cache.
In addition to its performance advantages, since the pool uses an array to store its objects, it is possible for certain structures to avoid storing full pointers to objects allocated from a pool instead using a pool_idx_t thus saving memory or allowing better caching.
◆ POOL_IDX_MAX
The maximum index value for pool.
Definition at line 29 of file pool.h.
◆ POOL_TAG_INC
The amount to increment the tag by in the tagged free list.
Definition at line 31 of file pool.h.
◆ pool_idx_t
Pool index type.
Definition at line 27 of file pool.h.
◆ pool_init()
Initialize a pool.
- Parameters
-
| pool | Pointer to the pool structure to initialize. |
| elements | Pointer to the elements array. |
| capacity | Maximum number of elements. |
| elementSize | Size of each element. |
| nextOffset | Offset of a pool_idx_t variable within each element used for the free list. |
Definition at line 3 of file pool.c.
◆ pool_alloc()
Allocate an element from the pool.
- Parameters
-
| pool | Pointer to the pool to allocate from. |
- Returns
- The index of the allocated element, or
POOL_IDX_MAX if the pool is full.
Definition at line 20 of file pool.c.
◆ pool_free()
Free an element back to the pool.
- Parameters
-
| pool | Pointer to the pool to free to. |
| idx | The index of the element to free. |
Definition at line 48 of file pool.c.