Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
When you call malloc(100) on Linux, glibc's ptmalloc searches free lists, may mmap fresh pages from the kernel, and returns a pointer aligned to 16 bytes. Your exercise strips that down to a fixed char heap[4096] and an explicit Block header: size, used flag, and next pointer. That header-before-payload layout is the same idea jemalloc and tcmalloc use, just with fancier bookkeeping.
cLoading…
Returning user memory means skipping the header: (char*)block + sizeof(Block). Finding the header from a user pointer reverses that subtraction.
For this exercise, you will finish my_malloc and implement my_free with coalescing on a static buffer. This task asks you to see allocation as list surgery, because heap exploitation CVEs and allocator tuning both start with understanding these block headers.
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 my_malloc and my_free functions using a fixed-size static buffer as the heap.
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