How can I know how much memory my process uses?

Posted on 2003-10-30
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.

Question by:rchc
  • 4
  • 2
LVL 10

Expert Comment

ID: 9649764
What platform r u on

Author Comment

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

Expert Comment

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

Have a look at this site

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

LVL 10

Expert Comment

ID: 9649929
A similar question was previously asked

here's a good discussion for the same


Author Comment

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?

Accepted Solution

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

Expert Comment

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 ...;

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 132
Adjust Mfcapp 29 160
How to set environment variables in C 2 77
Why does module make constant click noise ? 9 125
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now