libmemalloc
v4.0.00
Modern Memory Allocator
|
libmemalloc is a comprehensive, drop-in C memory management library that elevates your application’s heap to a fully introspectable, high-performance subsystem. It offers three tunable allocation strategies—First-Fit, Next-Fit (with optional “last allocated” pointer tracking), and Best-Fit—enabling you to balance speed, fragmentation, or memory footprint on each call. Small allocations are serviced via segregated free lists organized into configurable size classes for constant-time inserts and removals, while large requests (≥ 128 KiB) automatically bypass sbrk in favor of mmap to minimize fragmentation and leverage OS paging efficiencies. An optional background mark-and-sweep garbage collector can be activated to transparently reclaim unreachable blocks, eliminating manual free() calls in scenarios where automatic cleanup is preferred. Every block is protected by magic numbers and footer canaries to detect header corruption or buffer overflows at runtime. Internal locking guarantees thread safety in multithreaded environments, and seamless Valgrind integration annotates a dedicated MemPool for precise leak and fragmentation reporting. With configurable log verbosity (ERROR, WARN, INFO, DEBUG), live allocation maps, fragmentation metrics, and on-demand diagnostics, libmemalloc gives you unparalleled visibility into your program’s memory behavior. Integration couldn’t be simpler: link against the provided static (.a) or shared (.so) library, include libmemalloc.h, and replace your standard malloc/free calls with the intuitive MEM_* API to transform your heap—no other source modifications required.