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 worksRepeated allocate/free patterns of different sizes leave unusable gaps between live blocks. Visualizing free holes explains why long-running servers restart or switch to pool allocators even when total bytes look fine.
Map each heap byte to a character: . free, # allocated, | boundary. After a fragmentation script, long runs of . between # clusters show external fragmentation.
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 simulate a simple heap and print colored ASCII maps after a fragmentation workload. This exercise requires identifying a hole that blocks a large allocation request.
External fragmentation is when plenty of memory is free but no single hole is big enough. Build a heap allocator over a fixed arena of 16-byte units, with first-fit, best-fit and worst-fit placement, draw the heap as an ASCII map, and measure fragmentation. Watch a request fail while the total free space would have been enough.
cLoading…
ceil(BYTES / 16) contiguous units. Holes are maximal runs of free units in address order, and free neighbours merge automatically.A..Z then a..z (cycling), which is drawn in its units. Free units are ..FAILED, need N contiguous units, M free in total and counts as a failure.malloc NAME: rejected (BYTES < 1, a live duplicate name, or 128 blocks), free NAME: invalid free, heap: 1..1024 units, and policy: first, best or worst.cLoading…
The map shows 32 units per row, prefixed by the row's byte offset in 5 columns. The last row may be shorter.
Input:
cLoading…
Output:
cLoading…
Hidden tests cover best-fit and worst-fit choosing different holes on the same trace, several failures despite enough total space, a heap that is not a multiple of 32 units, symbols cycling past Z, and invalid commands.