Results 1 to 5 of 5
Hi All,
Have a few questions regarding malloc.
1. How does "malloc" system call attocate memory?
2. Are there any env variables that can affect the allocation of memory in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-21-2008 #1
malloc
Hi All,
Have a few questions regarding malloc.
1. How does "malloc" system call attocate memory?
2. Are there any env variables that can affect the allocation of memory in malloc?
3. Is fragmentation of heap and non availability of heap the only reasons for malloc failure?Linux Rocks!!!!
-- Rinjo
Setup: Oses: Windows 7 HB and Fedora 17 dual boot Hardware: HP Pavilion G6-2005AX laptop, AMD A8 Quad Core, 4 GB RAM, 1.5 GB dual Graphics card, 500GB HDD.
- 10-22-2008 #2Just Joined!
- Join Date
- Oct 2008
- Posts
- 6
write one line program that use malloc, and then use strace on it.
- 10-26-2008 #3Just Joined!
- Join Date
- May 2008
- Posts
- 55
1. How does "malloc" system call attocate memory?
-> kernel does not allocate memory as soon as you do malloc, but it only prepares vmas. and when you actually access it it allocates page because of page fault exception. if it was a read access then kernel allocates special page called zero page, which is called demand paging
2. Are there any env variables that can affect the allocation of memory in malloc?
I think no.
3. Is fragmentation of heap and non availability of heap the only reasons for malloc failure?
there is nothing like fragamentation of heap, because your process understands virtual address space,not physical. it is kernel who understands it.
so for malloc process may sleep or other pages could be swapped out, if the swap area is full and as physical memory fragamented (internal fragmentation) then malloc may fail.
- 11-01-2008 #4
Hi Matt,
Thanks for your detailed answer to my query.
Linux Rocks!!!!
-- Rinjo
Setup: Oses: Windows 7 HB and Fedora 17 dual boot Hardware: HP Pavilion G6-2005AX laptop, AMD A8 Quad Core, 4 GB RAM, 1.5 GB dual Graphics card, 500GB HDD.
- 11-20-2008 #5Just Joined!
- Join Date
- Nov 2008
- Location
- Bangalore
- Posts
- 4
For detailed explanation on how malloc allocates memory visit these sites:
CS360 Lecture notes -- Malloc Lecture #1
CS360 Lecture notes -- Malloc Lecture #2


Reply With Quote
