Master the fundamental concepts of memory optimization through this focused micro-challenge.
Arena allocators (also called region allocators) hand out slices from growing blocks and free everything when the arena resets. LLVM's BumpPtrAllocator, Rust's bumpalo, and many compilers use arenas per function or per compilation unit.
When the current block fills, allocate a larger block, link it, and continue bumping. Reset walks blocks or reuses the first chunk.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will implement a multi-block arena with reset and measure allocation throughput. This exercise requires using the arena for a batch of objects then reclaiming all with one reset call.
Implement an arena allocator in C.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github