Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
malloc on glibc returns 16-byte aligned memory because SSE and AVX loads fault or slow down on misaligned addresses. An int wants 4-byte alignment; a double wants 8. The check is simple: (uintptr_t)ptr % align == 0.
Aligned heap block: over-allocate, bump the pointer up to the next aligned boundary, stash the original malloc pointer just before the aligned region so free can find it:
cLoading…
Stack bump allocator: advance a current pointer through a fixed buffer; pop resets it. LLVM and game engines use this pattern for per-pass temporaries.
free on the stack side, only resetFor this exercise, you will implement aligned_malloc, aligned_free, and a small stack allocator with push/pop. This task asks you to verify alignment with uintptr_t checks, because mysterious SIMD crashes in production are almost always an alignment bug.
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 aligned memory allocation and a simple stack allocator.
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