A single header generic pool allocator.
- Include
pool.h
(pool.h
requiresslist.h
so make sure your compiler can find that too). - Create an instance of the pool types and functions by passing a name, type, and size to the macro
POOL
likePOOL(my_pool, int, 100)
. - Create one or more instances of the pool type you created like
struct pool_my_pool my_pool_instance;
. Each instance is capable of allocating up to 100 (the size you pass toPOOL
) objects of the type you specified. - Allocate and free objects with
int *obj = pool_my_pool_alloc(&my_pool_instance);
andpool_my_pool_free(&my_pool_instance, obj);
.
See test/test_pool.c
.