malloc is not the only way to allocate memory ⚡
The actual memory allocation and deallocation happen with brk, sbrk, and mmap system calls and malloc is a convenient wrapper over them. Some of the popular and widely adopted malloc implementations are
- jemalloc
- tcmalloc
Popular packages like Redis and Varnish have switched to jemalloc for better performance and Cloudflare has switched to tcmalloc and has decreased memory usage by 2.5 times.
These implementations are open-sourced and do spend some time going through their code on GitHub and re-implement some fragments of it.
⚡ I keep writing and sharing these engineering nuggets, so if you are keen on learning them, follow along.
arpitbhayani.me/courses