20#ifndef VL_POOL_DEFAULT_SIZE
21#define VL_POOL_DEFAULT_SIZE 16
31#if defined(VL_U64_T) && defined(VL_U32_T)
32#define VL_POOL_INDEX_T VL_U64_T
33#define VL_POOL_ORDINAL_T VL_U32_T
34#define VL_POOL_LOOKUP_MAX 0xFFFFFFFF
35#define VL_POOL_INVALID_IDX 0xFFFFFFFFFFFFFFFF
36#elif defined(VL_U32_T) && defined(VL_U16_T)
37#define VL_POOL_INDEX_T VL_U32_T
38#define VL_POOL_ORDINAL_T VL_U16_T
39#define VL_POOL_LOOKUP_MAX 0xFFFF
40#define VL_POOL_INVALID_IDX 0xFFFFFFFF
41#elif defined(VL_U16_T) && defined(VL_U8_T)
42#define VL_POOL_INDEX_T VL_U16_T
43#define VL_POOL_ORDINAL_T VL_U8_T
44#define VL_POOL_LOOKUP_MAX 0xFF
45#define VL_POOL_INVALID_IDX 0xFFFF
47#error Failed to configure vl_pool types.
55typedef struct vl_pool_node vl_pool_node;
65typedef struct vl_pool_node
67 VL_POOL_ORDINAL_T totalTaken;
68 VL_POOL_ORDINAL_T blockSize;
69 VL_POOL_ORDINAL_T blockOrdinal;
70 vl_pool_node* nextLookup;
197static inline void vlPoolInit(
vl_pool* pool, vl_uint16_t elementSize)
260static inline vl_pool* vlPoolNew(vl_uint16_t elementSize)
#define VL_DEFAULT_MEMORY_ALIGN
Default memory alignment. Defaults to maximum system word size.
Definition vl_memory.h:60
VL_STRUCTURE_INDEX_T vl_dsidx_t
Index type for data structures.
Definition vl_numtypes.h:75
vl_dsidx_t freeCapacity
Definition vl_pool.h:153
VL_API vl_pool_idx vlPoolTake(vl_pool *pool)
Takes a new index from the fixed pool, which corresponds to a valid memory location within the pool.
Definition vl_pool.c:105
VL_API void vlPoolReturn(vl_pool *pool, vl_pool_idx idx)
Gives the specified index back to the fixed pool, allowing it to be re-used.
Definition vl_pool.c:150
VL_API vl_pool * vlPoolNewAligned(vl_uint16_t elementSize, vl_uint16_t alignment)
Allocates and initializes a new fixed pool instance with specific alignment.
Definition vl_pool.c:326
VL_API vl_pool * vlPoolClone(const vl_pool *src, vl_pool *dest)
Clones the specified source fixed pool.
Definition vl_pool.c:268
vl_uint16_t elementAlign
Definition vl_pool.h:143
VL_API void vlPoolFree(vl_pool *pool)
De-initializes the specified pool instance.
Definition vl_pool.c:189
vl_pool_idx growthIncrement
Definition vl_pool.h:145
VL_API void vlPoolInitAligned(vl_pool *pool, vl_uint16_t elementSize, vl_uint16_t alignment)
Initializes the specified fixed pool instance with specified element size and alignment.
Definition vl_pool.c:68
VL_API void vlPoolDelete(vl_pool *pool)
De-initializes and deletes the specified fixed pool instance.
Definition vl_pool.c:335
vl_pool_node ** lookupTable
Definition vl_pool.h:150
vl_pool_node * lookupHead
Definition vl_pool.h:151
vl_dsidx_t lookupTotal
Definition vl_pool.h:147
vl_pool_idx * freeTop
Definition vl_pool.h:155
VL_API void vlPoolReset(vl_pool *pool)
Resets the specified pool to its initial state.
Definition vl_pool.c:218
VL_API void vlPoolClear(vl_pool *pool)
Clears the specified pool.
Definition vl_pool.c:176
VL_API void * vlPoolSample(vl_pool *pool, vl_pool_idx idx)
Samples the specified fixed pool and retrieves a pointer to the memory associated with the specified ...
Definition vl_pool.c:169
vl_dsidx_t lookupCapacity
Definition vl_pool.h:148
VL_API void vlPoolReserve(vl_pool *pool, vl_dsidx_t n)
Ensures that at least n additional elements can be taken without triggering further allocations.
Definition vl_pool.c:245
vl_pool_idx * freeStack
Definition vl_pool.h:154
vl_uint16_t elementSize
Definition vl_pool.h:142
VL_POOL_INDEX_T vl_pool_idx
Definition vl_pool.h:53
Fixed-size memory pool with stable indices and geometric growth.
Definition vl_pool.h:141