Master the fundamental concepts of memory optimization through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksArena 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.
An arena is a bump allocator that never runs out: when the current block is full it chains a new, larger block, and everything is freed at once when the arena is destroyed. Add temporary scopes (save a position, then roll back everything allocated after it, including whole blocks) and clear (keep the first block for reuse). Track exactly where bytes are wasted.
cLoading…
round_up(offset, ALIGN). If it does not fit, start a new block of size max(2 * current block size, SIZE) and place the allocation at its offset 0 (block bases are page-aligned). The unused tail of the old block is lost.arena: 16..1048576 bytes, alloc NAME: bad size or alignment, alloc NAME: too many blocks (32 at most), temp: too deep, and temp end: no temp scope.cLoading…
Input:
cLoading…
Output:
cLoading…
Hidden tests cover an allocation bigger than twice the current block (it gets its own oversized block), nested temp scopes, a temp scope that stays inside one block, large alignments, clear followed by reuse, and invalid sizes, alignments and scopes.