?
Solved

How can I know how much memory my process uses?

Posted on 2003-10-30
7
Medium Priority
?
244 Views
Last Modified: 2011-09-20
I'm runing a program that uses a lot of memory. How can I know how much memory does it use.
I would like to print the amount of memory it uses before aborting the porgram due to lack of memory.

Thanks
0
Comment
Question by:rchc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9649764
What platform r u on
0
 

Author Comment

by:rchc
ID: 9649790
I run on Solaris 5.8 or linux
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9649895
I think you should keep track of your dynamic memory allocation functions - malloc, calloc, free, realloc etc

Also,
Have a look at this site

 http://www.dmalloc.com

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9649929
A similar question was previously asked

here's a good discussion for the same

http://www-level3.experts-exchange.com/Operating_Systems/Unix/Q_20727263.html

0
 

Author Comment

by:rchc
ID: 9649930
My code is a legacy one with thousands of lines. I can't keep track of each allocation.
I'm seeking a function that can tell me the amounr of memory allocated and or the free memory.
Is there such a function?
0
 
LVL 5

Accepted Solution

by:
mtmike earned 1000 total points
ID: 9649946
Use getrusage() to get the data size of the process or mallinfo() to get memory allocator statistics.
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9650024
As I said, the link on EE would be helpful
I am listing one of the solutions from there

Say u are using malloc for dynamic allocation

then just do this

#define malloc malloc_wrapper

malloc_wrapper ( same_arguments_as_malloc )
{
     /* do the accounting */
     malloc ( ... );
     return ...;
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question