A single header buddy memory allocator for C & C++
buddy_realloc
that allows it to ignore data. Useful for resizing buffers when there is no longer any interest in their content.External changes:
buddy_walk
callback is now invoked for free slots in addition to allocated ones and has an extra parameter to distinguish between free and allocated.buddy_fragmentation
return type is now an unsigned char
that ranges between 0 and 255 and no float
types are used. This way fragmentation can be reported when used in environments that don't support the float
type.Internal changes:
two_to_the_power_of
helper function that returns size_t
is used in place of manual power of two calculations.Misc:
Two years and nine months have passed since this project started and it has now reached the 1.0.0
milestone. Thanks to all contributors and users for their interest in it.
{0}
initializers to facilitate interop with strict C++ compilers
stdio.h
only when BUDDY_PRINTF
is not definedBUDDY_PRINTF
, BUDDY_HEADER
and BUDDY_FRAG_OPTIONAL
added to allow conditional inclusion of functionality and setting a suitable printf-like function for the debug functions.This is a significant performance update achieved by reducing the number of tree reads during allocation.
Running bench.c
using gcc -O2
on v0.7 takes 20 seconds vs 16 seconds on v0.7.1
Running bench.c
using clang -O3
on v0.7 takes 16 seconds vs 13 seconds on v0.7.1
buddy_arena_free_size
that reports the remaining free space in the arena.
Note that this is a sum of all slots and not necessarily continuous memory.BUDDY_ALLOC_ALIGN
define is still supported.
This is a change in the internal structure of the allocator which can impact serialized instances. There's no impact to regular users.BUDDY_ALLOC_SAFETY
define, always use safety checks.buddy_fragmentation
function that measures and reports fragmentation in the arenabuddy_set_left_bias
and buddy_set_optimal_fit
functions to configure allocation behavior on demand