Mostly comprehensive C memory allocation library. Has equivalents for
free(3)
,malloc(3)
, andrealloc(3)
.
- Memory safe mode (on by default,
-DBALLOC_SAFE
) that resets (toNULL
) the memory when newly-allocated and free'd, rather than junk memory. - Resets free'd pointers, preventing double-
free()
errors and vulnerabilities. - Keeps track of allocated memory, able to be retrieved at any time with
ba_size()
. - Errors on a failed allocation, rather than a hard to trace
NULL
pointer reference.
Read through balloc.h
for the documentation and forward declarations. When in doubt, read the source code. For examples, take a look at the tests.
Building balloc requires:
- bash
- C compiler (gcc by default, change with
make CC=...
) - file archiver (ar by default)
$ make
This will build a shared library file (which can be compiled against) to out/libballoc.a
and will then run the tests.
You can specify a location to build the shared library to like so:
$ make LIB_OUT=/my/custom/dir/libballoc.a
Tests will be run by the test.sh
file. Run tests only like so:
$ make test
MIT licensed. Enjoy :)