
Optimizing Memory usage with mmap - Phase 6 Mini Malloc
This is Phase 6 of creating a mini malloc! Here, I will implement mmap 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 on my github account: [ https://github.com/moonlitpath1/mini-malloc ] For large allocations, mmap is better than sbrk since while freeing, mmap block with munmap returns memory back to the kernel unlike sbrk blocks which stay in your heap forever. To observe this in person, I created a simple test_threshold.c code that i traced with strace #include <stdlib.h> int main () { void * ptr = malloc ( 256 * 1024 ); //256kb free ( ptr ); return 0 ; } Result: anu@laptop:~/anu/programming/systems_progg/mini-malloc$ gcc test_threshold.c -o out && strace -e
Continue reading on Dev.to
Opens in a new tab



