LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 06-22-2006, 09:54 PM   #1
johnarg
LQ Newbie
 
Registered: Jun 2006
Posts: 2

Rep: Reputation: 0
How Linux allocates memory for malloc in a program


Hi,
I am new to Linux. I am allocating memory using malloc in a C program.
****************************
int *ptr;
if((ptr = malloc(sizeof(int)*1024*2000)) == NULL)
{
fprintf(stdout, "Malloc failed\n");
}

while(1)
{
//To make program running continuosly
}
******************************
When I check the memory being used by the system for this process using top command, it shows 308KB(RSS).
Could someone help me, why the difference occured in the memory allocated in the program using malloc and the memory allocated by the System.
I want to know how Linux allocates memory for a process.

Please help ASAP. Thanks in advance.
 
Old 06-24-2006, 08:52 AM   #2
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
I would have to look into who linux allocates memory but I would warn you that it looks like you are mallocing about 8 Megs of memory. That is kind of risky with malloc since it does not do a check that something else is using that memory and you could write over other program memory space. Just a warning.
 
Old 06-25-2006, 08:15 PM   #3
johnarg
LQ Newbie
 
Registered: Jun 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by FLLinux
I would have to look into who linux allocates memory but I would warn you that it looks like you are mallocing about 8 Megs of memory. That is kind of risky with malloc since it does not do a check that something else is using that memory and you could write over other program memory space. Just a warning.


Thank you very much for ur suggestion. However, I want to check a program for Memory usage. I am checking it with RSS of top command. However, I can I be sure that RSS shows actual memory usage. If u could pls. suggest something, pls. advice me.
Thanking u in advance.
 
  


Reply

Tags
linux, memory


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to start valknut says "malloc(): memory corruption: 0x08211838 ***΅ shyamsundar Linux - Software 3 05-30-2006 06:04 AM
glibc detected *** malloc(): memory corruption: abefroman Linux - Software 2 04-12-2006 01:12 PM
Cinelerra Crashes While Rendering - malloc(): memory corruption uryagi Linux - Software 0 02-27-2006 03:07 PM
malloc() and system memory spaceman27 Programming 8 04-25-2005 10:58 AM
Out Of Memory - A caring malloc? cyent Programming 3 09-18-2002 10:38 AM


All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration