Master the fundamental concepts of memory optimization through this focused micro-challenge.
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 worksValgrind Massif records heap snapshots over time so you can see peak usage and which call stacks allocated it. Chrome's allocator telemetry and Rust's dhat serve the same goal: find leaks, spikes, and unexpected strdup hot paths.
Run with --tool=massif, open massif.out in ms_print or massif-visualizer. Look for stairs that never descend (leak) and sudden peaks (batch allocation).
bashLoading…
-g for symbolic stacks--pages-as-heap=yes includes mmap allocationsKeep 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 run Massif on a program with deliberate allocation patterns and identify the top allocator stack. This exercise requires reporting peak bytes and the responsible function.
Valgrind's massif answers "where did my heap peak, and who was using it?", and memcheck's leak check answers "what was never freed?". Build a small heap profiler that replays an allocation trace. It tracks useful bytes plus the allocator's per-block admin overhead, finds the peak, breaks the peak down by allocation site, and reports leaks by site at the end.
cLoading…
massif --time-unit=B: the total bytes ever allocated. malloc adds SIZE, and realloc adds only its growth.end, grouped by site in order of first appearance.malloc ID: id already live, malloc ID: rejected (negative size), free ID: invalid free, and realloc ID: invalid.cLoading…
Input:
cLoading…
Output:
cLoading…
Hidden tests cover a peak driven by many tiny blocks (overhead dominates), realloc growth and shrink, a zero admin cost, ties between sites, a trace with no leaks, and invalid frees and reallocs.