Link to home
Start Free TrialLog in
Avatar of rchc
rchc

asked on

How can I know how much memory my process uses?

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
Avatar of Sys_Prog
Sys_Prog
Flag of India image

What platform r u on
Avatar of rchc
rchc

ASKER

I run on Solaris 5.8 or linux
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

A similar question was previously asked

here's a good discussion for the same

http://www-level3.experts-exchange.com/questions/20727263/knowing-the-memory-consumption-of-my-process.html

Avatar of rchc

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of mtmike
mtmike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ...;
}