memory usage

T

Tim Quon

Hi there,

is there a function in standard C to find out how much memory is used?
Or better, a function to find out how much memory is used by the
application itself.

Thanks
 
A

Andreas Kahari

is there a function in standard C to find out how much memory is used?

No, sorry. You could yourself keep track of the number of bytes
allocated with malloc() et al., but AFAIK this does not need
to be exactly the amount of memory that your application makes
use of on the computer. For that you will probably need an
operating system utility such as 'ps' or 'top' on Unix systems.
 
T

Tim Quon

No, sorry. You could yourself keep track of the number of bytes
allocated with malloc() et al., but AFAIK this does not need
to be exactly the amount of memory that your application makes
use of on the computer. For that you will probably need an
operating system utility such as 'ps' or 'top' on Unix systems.

Do you know how to use the mstats() function.
 
B

Ben Pfaff

Tim Quon said:
Do you know how to use the mstats() function.

There is no standard mstats() function. If your system has one,
please refer to a system-specific manual, newsgroup, etc., to
find out more information about it.
 
E

E. Robert Tisdale

Tim said:
Is there a function in standard C to find out how much memory is used?
No.

Or better, a function
to find out how much memory is used by the application itself.

You would need to make an implementation dependent
operating system call. For UNIX, take a look at


SYNOPSIS
#include <sys/resource.h>

int getrusage(int who, struct rusage *usage);

CONFORMING TO
SVr4, BSD 4.3
 
E

Emmanuel Delahaye

In 'comp.lang.c' said:
is there a function in standard C to find out how much memory is used?
Or better, a function to find out how much memory is used by the
application itself.

No, and in real life, it will probably be a nonsense, because most of the
application are constantly allocating/freeing memory. (For static memory,
just read the mapping made by your linker)

That said, on embedded systems, I use a wrapper to malloc()/free() that
counts the alloc/free operations (useful to detect a memory leak), and
records the size of the biggest allocated chunk (useless at the moment).
 
E

Emmanuel Delahaye

In 'comp.lang.c' said:
Do you know how to use the mstats() function.

Non standard, hence off-topic here. Please ask on a newsgroup dedicated to
your system or implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top