A single header buddy memory allocator for C & C++
Allow defragmentation of the arena to happen in realloc.
buddy_walk
, added more tests for itbuddy_free
that prevents freeing when called with a free node leading up to a allocated parent on a different address.buddy_safe_free
- a safer free function with a size parameter that will not alter the allocator's state if the provided size does not fit the allocated slot size.buddy_walk
- a callback iterator that walks through all allocated slots which can be used for mailboxes or managed heaps.v0.2.1 is a performance-related release
v0.2.0 contains changes for better interoperability with different compilers
_Bool
is replaced with unsigned int
to avoid issues between C's _Bool
and C++'s bool
typesbuddy_is_empty
functionFurther performance improvements. The values in the tree are now unary encoded and read faster using a popcount builtin.
Debug build performance of buddy_brk.c vs glibc's release malloc on stress-ng.
Note that buddy_brk.c does not return memory to the kernel, so take it with a grain of salt. Still, it is less than twice as slow as glibc now :)
$ env LD_PRELOAD=./buddy_shared.so ~/dev/stress-ng/./stress-ng --malloc 1 --malloc-ops 100000 2>&1
stress-ng: info: [2896] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
stress-ng: info: [2896] dispatching hogs: 1 malloc
stress-ng: info: [2896] successful run completed in 0.16s
$ env ~/dev/stress-ng/./stress-ng --malloc 1 --malloc-ops 100000 2>&1
stress-ng: info: [2900] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
stress-ng: info: [2900] dispatching hogs: 1 malloc
stress-ng: info: [2900] successful run completed in 0.11s