What does malloc() do in Linux
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > What does malloc() do in Linux




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    What does malloc() do in Linux  
Zheng Da


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-19-05 10: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.






[ Post a follow-up to this message ]



    Re: What does malloc() do in Linux  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-19-05 10: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





[ Post a follow-up to this message ]



    Re: What does malloc() do in Linux  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-19-05 10: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.





[ Post a follow-up to this message ]



    Re: What does malloc() do in Linux  
Zheng Da


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-20-05 07: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






[ Post a follow-up to this message ]



    Re: What does malloc() do in Linux  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-20-05 12:53 PM

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 memor
y
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






[ Post a follow-up to this message ]



    Re: What does malloc() do in Linux  
Jonathan Bartlett


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-20-05 11: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:40 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register