[ back to toc ]

memory usage

Date: 2002/04/16 10:37

Q:
Hi,

I got this program (with source code) and I wanted to see how much
memory it uses.

I want to have a variable that maintains how
many bytes are presently allocated by the program.

Throughout the code they use calloc, realloc and
free. Now, I can count how much was assigned by
calloc, since it's trivial. The problem is with
realloc. Since I don't know what the size of the
array was before realloc was called, I can't figure out how many new bytes
are being introduced
upon realloc. Same goes for free, I can't figure out how big the dynamic
array was at first by simply getting a pointer of the array to be
deallocated.

I have tried using sizeof, but that is a compile-time function and knows
nothing about the
dynamically allocated space.
I have tried using mallinfo's uordblks, but that does not register the
memory that has been realloced.
I want to have way to run my program from the
command line and somehow spit out how much memory
was used by it.
I am on a Linux system.

levan
A:
Dear *NAME-DELETED*

there are tools that do it for you. I know one that is ggod at discovering
freed memory reause, and is called Electric Fence.

Visit FreshMeat.net for more information.

regards,
Peter

[ back to toc ]