• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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.

  • 4
  • 2
1 Solution
What platform r u on
rchcAuthor Commented:
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

Have a look at this site


Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

A similar question was previously asked

here's a good discussion for the same


rchcAuthor Commented:
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?
Use getrusage() to get the data size of the process or mallinfo() to get memory allocator statistics.
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 ...;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now