| Author |
What does malloc() do in Linux
|
|
| Zheng Da 2005-06-19, 5:51 pm |
| I want to know what malloc() do in Linux.
Some books say malloc() will call brk() and mmap()
I have tried to find the the source code of malloc() in glibc.
But it seems the code I find in glibc is not for Linux, and it doesn't
call brk() and mmap().
Could any one give me the source code of malloc() for Linux?
Thank you.
| |
| Måns Rullgård 2005-06-19, 5:51 pm |
| "Zheng Da" <zhengda1936@gmail.com> writes:
> I want to know what malloc() do in Linux.
> Some books say malloc() will call brk() and mmap()
> I have tried to find the the source code of malloc() in glibc.
> But it seems the code I find in glibc is not for Linux, and it doesn't
> call brk() and mmap().
> Could any one give me the source code of malloc() for Linux?
It's in glibc and it does call both brk/sbrk and mmap.
--
Måns Rullgård
mru@inprovide.com
| |
| Paul Pluzhnikov 2005-06-19, 5:51 pm |
| Måns Rullgård <mru@inprovide.com> writes:
What source file(s) are you looking at?
[vbcol=seagreen]
> It's in glibc ...
More precisely, it's in malloc/malloc.c; start with the
public_mALLOc() function.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| Zheng Da 2005-06-20, 2:48 am |
| I find it now.
Thank you
I just search malloc in sourceinsight, so I didn't get the right one.
The public_mALLOc() seems very complex, must more complex than I thought
| |
| Michael B Allen 2005-06-20, 7:53 am |
| On Sun, 19 Jun 2005 23:32:03 -0700, Zheng Da wrote:
> The public_mALLOc() seems very complex, must more complex than I thought
If you want an example of a very simple allocator look at the malloc
implementation in Plauger's _The Standard C Library_.
I've also written a simple circular linked list of cells type of allocator
[1] although it doesn't call sbrk or mmap because it sub-allocates memory
from a larger chunk privided by the user when the allocator is initialized.
Mike
[1] http://www.ioplex.com/~miallen/libmba/dl/src/suba.c
| |
| Jonathan Bartlett 2005-06-20, 6:05 pm |
| Zheng Da wrote:
> I find it now.
> Thank you
> I just search malloc in sourceinsight, so I didn't get the right one.
> The public_mALLOc() seems very complex, must more complex than I thought
If you want to see a simple memory manager, see my article on memory
management:
http://www-128.ibm.com/developerwor...brary/l-memory/
It also goes through other aspects of memory management. You can find
an assembly language version of the allocator in my book listed in my
signature.
Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
|
|
|
|