Implementation details of malloc() and free() functions in glibc

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux

Issue

  • Need to understand how glibc's malloc() and free() functions work internally.

Resolution

Since glibc in Red Hat Enterprise Linux is based on dlmalloc implementation (aka ptmalloc2), the basic concepts of the allocation are similar to that described in Doug Lea's article A Memory Allocator. There have however been significant changes and improvements to th internals and hence, the best resource for understanding the internals is the glibc source code. malloc/malloc.c in the glibc source shipped in RHEL has extensive comments describing the architecture of the memory allocation allocator as well as the rationale behind the design.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments