balloc — Bounded Pre-Allocated C Allocators
Abstract
Single-header C library (325 LOC) implementing Arena, Fixed-Size Pool, and First-Fit Coalescing Heap strategies over a 64-byte aligned backing slab.
1. Strategies¶
Backing slab (64-byte aligned, allocated once at _create) |-- ba_arena O(1) bump pointer, power-of-two align, bulk reset |-- ba_pool O(1) fixed-size slots via intrusive LIFO free list +-- ba_heap bounded first-fit with block split & coalescing
2. Design Notes¶
-
No runtime syscalls: full capacity is reserved once in
_create(). Replacing the backing slab with a static buffer makes the core freestanding. -
Intrusive free list:
ba_poolstores the next-pointer inside each freed slot for zero per-object metadata overhead. -
Split and coalesce:
ba_heapsplits oversized blocks on alloc and immediately coalesces adjacent free blocks on free.
3. Benchmarks vs glibc (Linux x86_64)¶
- Pool (64 B)
- 3.46 ns/op vs 9.86 ns/op glibc (2.8x faster)
- Heap (16 B)
- 7.22 ns/op vs 12.43 ns/op glibc
- Mixed (8-256)
- 34.09 ns/op vs 55.94 ns/op glibc
- Tests
- 38/38 passing (11 arena, 10 pool, 17 heap)