Malloc statistics?

J

Jason

Greetings,
Is there a reliable and portable way of getting malloc statistics within
a running C program? I have tried to use the mallinfo() command, but it
isn't portable (reports different things on linux and HP), and Purify
reports memory access violations with it.

At any given point in a program, I would like to grab total used memory
for the process. Does anyone have a good way of doing this?
Thanks
Jason
 
R

Richard Heathfield

Jason said:
Greetings,
Is there a reliable and portable way of getting malloc statistics within
a running C program? I have tried to use the mallinfo() command, but it
isn't portable (reports different things on linux and HP), and Purify
reports memory access violations with it.

At any given point in a program, I would like to grab total used memory
for the process. Does anyone have a good way of doing this?

I use a malloc wrapper (wot I wrote myself) which writes memory usage
information to a log file for later analysis. You could use a similar
technique to track memory usage in a way accessible to your program.

You might want to make it a macro, so that you can easily switch between a
statistics-enabled version and a no-nonsense version (if you'll forgive the
expression).
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top