Master the fundamental concepts of memory optimization through this focused micro-challenge.
Bump (arena) allocators hand out memory by advancing an offset into a preallocated block. Freeing individual objects is unsupported; reset the whole arena in one instruction. Compilers, parsers, and per-request HTTP handlers use bump pointers because allocation is a pointer add.
Request n bytes aligned to alignof(max_align_t). If the arena has space, bump offset and return the previous pointer. Otherwise grow or abort.
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 bump allocator and use it for thousands of short-lived objects. This exercise asks you to show allocation speed versus malloc and document the reset strategy.
Implement bump allocator for fast temporary allocations.
Requirements:
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