this repo explores the inner workings of memory allocation by implementing a small version of the malloc function in C. in this project i'm aiming to get a deep understanding of how the operating system manages memory and the concepts behind dynamic memory allocation.
How it works
smalloc(size)roundssizeup to 16, then walks the chunk list (g_chunk→next_chnuk→ …) for the first free chunk that is big enough. If none fits, itmmaps a new zone (16 KiB, or bigger for large requests) and appends it.- If the chosen chunk is much bigger than needed, it is split: the tail becomes a new free chunk right after it.
s_free(ptr)finds the chunk, setssts = false, and merges it with free neighbours that sit right next to it in memory, so space doesn't break into tiny pieces.show_mem()prints every chunk with its address, size and state.
make
./smalloc # runs main.c: allocate, free, reuse, and print the chunk listDiagrams in docs/ are generated SVGs, drawn to match the code in this repo.