MMCTX (Memory Management ConTeXualizer), is a tiny (< 300 lines), single header C99 library that allows for easier memory management by implementing contexts that remember allocations for you and provide
It provides a simple interface and two possible implementations , one using dynamic arrays and another using linked lists.
Offered under either the GPLv3 or the LGPLv3, at your choice.
- For interface details , see mmctx.h.
- For an example, including help on choosing an implementation, see sample.c.
- For a toy benchmark , try bench.c.
It is suitable even for freestanding environments, as long as they can provide
stddef.h and implementations of the below, for MMCTX to wrap around and provide contextualized analouges :
void *malloc(size_t); void *calloc(size_t); void free(void *); void *realloc(void *,size_t);
Special thanks to :
- u/aioeu for suggestions and pointing out bugs, see : 1, 2, 3.
- u/oh5xno because this project is essentially my implementation of his words of wisdom, see : 1, 2, 3, 4 (though he modestly denies offering anything more than idioms).
- u/ceene, for reminding me that
ctx_callocwas not (v2.02 and older) checking for overflow, see this.
- u/must_make_do, for informing me on the suitability of the LGPL for this project, see this.