C – The version of malloc used on Linux

The version of malloc used on Linux… here is a solution to the problem.

The version of malloc used on Linux

I was just looking at the comment at the top of the malloc.c file in glibc and it says this:

You may already by default be using a C library containing a malloc
that is based on some version of this malloc (for example in
linux). You might still want to use the one in this file in order to
customize settings or to avoid overheads associated with library
versions.

I don’t understand why the glibc code would say that a certain version of Linux might use something different than the code in glibc malloc.c? Can someone help rephrase what it means? I think glibc malloc() is something that every linux will use for memory management?

Solution

I say this because the malloc implementation in glibc is based on ptmalloc, which is again based on Doug Lea malloc from which these comments originate. This malloc implementation has been imported and becomes the default implementation in glibc version 2.3.

Since the malloc implementation of ptmalloc/doug Lea is a separate library that you can use to replace the standard malloc() on your system, these comments are applied. But when that library was introduced into glibc, the comments were preserved.

Related Problems and Solutions