malloc is not the only way to allocate memory ⚡

Arpit Bhayani

Arpit Bhayani

Jan 16, 2024 • 1 min read


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

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses