Observing Malloc - Phase 0 Mini Malloc
This is a journey of how I built my first memory allocator. Note: The clues and guidance I mention below were given to me by an AI assistant, used purely to guide my understanding of concepts and s...

Source: DEV Community
This is a journey of how I built my first memory allocator. Note: The clues and guidance I mention below were given to me by an AI assistant, used purely to guide my understanding of concepts and syntax. The entire code is written by me, referencing the official glibc documentation throughout. I'm mentioning this explicitly because I believe in being honest about the learning process. The entire process and my code has been uploaded to my github account: [https://github.com/moonlitpath1/mini-malloc] Let's start! First, I'll build a mental model of what malloc does at the systems level by observing it's behavior. 0.1 : Using strace to see how kernel manages memory for ls Command to run anu@laptop:~$ strace -e trace=brk,mmap,munmap ls 2>&1 | head -40 [[dump/strace mmap, brk, munmap|Actual code output]] there are 2 ways to give memory to a program brk: extending the heap mmap: maps all the shared library files .so (that ls depends on) ── PHASE 1: Library Loading ───────────────────