Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
Arena allocators (region allocators) grab one big block and hand out slices by advancing an offset. Apache's apr_pool, protobuf arenas in Google services, and LLVM's AST allocation all use this pattern: allocate thousands of small objects, free everything in one reset or at scope end.
cLoading…
No per-object free, no fragmentation walks, cache-friendly contiguous layout.
You cannot reclaim one string in the middle of a frame without resetting the whole arena. Memory stays reserved until arena_free. That is acceptable when lifetimes are tied to a request, a compiler pass, or a game tick.
For this exercise, you will implement arena_create, arena_alloc, arena_reset, and arena_free on a 1024-byte buffer. This task asks you to measure bytes consumed via offset, because choosing arena vs malloc per object is one of the highest-impact architecture calls in systems C.
Keep the relevant man page, ABI doc, or Rust reference chapter open while you work. When your output disagrees with the reference implementation on the same machine, the mismatch is usually an alignment rule, an off-by-one terminator, or a register slot you misread in GDB.
An arena hands out memory by bumping an offset through one buffer and frees everything at once with a reset. Allocation is a pointer bump; there is no per-object free.
arena_create(size): allocate the Arena and its buffer, offset 0.arena_alloc(arena, size, alignment): round the offset up to the alignment, (offset + a - 1) & ~(a - 1), where a is a power of two, and return the buffer at that position. Advance the offset past the allocation. Return NULL when the allocation would pass the end of the buffer.arena_reset: offset back to 0; the buffer is kept for reuse.arena_free: free the buffer and the Arena.The arena is 1024 bytes.
One word selecting a scenario.
alloc: allocate 10 ints (alignment 8), 5 doubles (alignment 16) and 100 chars (alignment 1). The doubles start at offset 48, not 40: Allocated 188 bytes.reset: the alloc scenario, then reset: Allocated 188 bytes and After reset: 0 bytes.align: allocate 10 ints (alignment 8) and 5 doubles (alignment 16) and check the addresses: 8-byte aligned: YES and 16-byte aligned: YES.oom: ask for 1025 bytes: Out of memory handled (or OOM not detected if the allocator returned memory).alloc, then a reset with its After reset: 0 bytes line, then align, then oom.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 works