Master the fundamental concepts of rust for systems programming 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 worksRust routes global allocation through GlobalAlloc. Discord and others plug in jemalloc or mimalloc for fleet wins; embedded targets sometimes ship a bump allocator with no individual free. Your exercise implements the trait the standard library expects.
rustLoading…
size and align; both must be honored on returnalloc#[global_allocator]Align an offset with (offset + align - 1) & !(align - 1), bump past the allocation, never free until reset. Zero-sized layouts are valid edge cases.
For this exercise, you will implement a GlobalAlloc bump allocator on a fixed byte array. This task asks you to pass Layout through correctly, because misaligned returns corrupt Vec growth and produce impossible-to-debug segfaults deep inside std.
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.
Implement the policy behind a bump allocator, the kind you would put behind unsafe impl GlobalAlloc for an arena. Allocation just rounds the top pointer up to the requested alignment and bumps it. Freeing only helps when you free the most recent block. Everything else leaks until reset. Addresses are simulated: the arena starts at 0x1000.
One command per line. Numbers are decimal.
cLoading…
start + SIZE passes the arena's end, it is out of memory and nothing changes. Otherwise top = start + SIZE.cLoading…
N − top, or N − block start for a failed in-place resize.allocation when the count is 1. The unit is always bytes, even for 1.Errors: error: bad command: LINE, error: arena size must be 1..4096, error: no arena, error: bad number, error: name too long, error: NAME is already allocated (a live block has that name), and error: NAME is not allocated. For alloc, check in this order: numbers, layout, name length, duplicate name, space. For realloc: number, name, size 0 (invalid layout (size 0, align A)), then space.
Input:
cLoading…
Output:
cLoading…
(addr + align - 1) & !(align - 1) on the absolute address, and validate layouts the way Layout::from_size_align does.Hidden tests cover LIFO frees that reclaim padding, frees that leak, in-place grow and shrink, moving reallocs, out-of-memory at the exact boundary, invalid layouts, and reset followed by reuse.