memory monitoring

memory monitoring

Post by Timo Be » Wed, 28 Aug 2002 17:45:21



Hi,

I have got the following problem:

I need a way to get the memory size used by my program.
It should look like the following:

---<snip>---
int mem = getUsedMemory();

char * buffer = (char*)malloc(1024);

mem = getUsedMemory(); // now mem should be 1024 bytes bigger
---<snap>---

Is there already such e function or, if not, how can i implement
it?

Any pointers aprecciated,
-timo

 
 
 

memory monitoring

Post by Kasper Dupon » Wed, 28 Aug 2002 18:34:44



> Hi,

> I have got the following problem:

> I need a way to get the memory size used by my program.

Why?

Quote:> It should look like the following:

> ---<snip>---
> int mem = getUsedMemory();

> char * buffer = (char*)malloc(1024);

> mem = getUsedMemory(); // now mem should be 1024 bytes bigger
> ---<snap>---

Why do you expect malloc(1024) to increase the memory usage
by 1024 bytes?

Quote:

> Is there already such e function or, if not, how can i implement
> it?

Why not just count the number of bytes you malloc?

Quote:

> Any pointers aprecciated,
> -timo

--
Kasper Dupont -- der bruger for meget tid p? usenet.



 
 
 

memory monitoring

Post by Timo Be » Wed, 28 Aug 2002 21:07:23




>> Hi,

>> I have got the following problem:

>> I need a way to get the memory size used by my program.

> Why?

>> It should look like the following:

>> ---<snip>---
>> int mem = getUsedMemory();

>> char * buffer = (char*)malloc(1024);

>> mem = getUsedMemory(); // now mem should be 1024 bytes bigger
>> ---<snap>---

> Why do you expect malloc(1024) to increase the memory usage
> by 1024 bytes?

>> Is there already such e function or, if not, how can i implement
>> it?

> Why not just count the number of bytes you malloc?

I want to detect memory leaks in functions not written by myself.

-timo

 
 
 

memory monitoring

Post by Paul Pluzhniko » Thu, 29 Aug 2002 00:05:12



> > Why not just count the number of bytes you malloc?
> I want to detect memory leaks in functions not written by myself.

In that case, use one of the tools written for this purpose, such
as mpatrol, dmalloc, ccmalloc, valgrind, Insure++ ...

Did you search google for "memory leak detection" ?
There's gotta be hundreds of hits.

Cheers,
--
In order to understand recursion you must first understand recursion.

 
 
 

memory monitoring

Post by Timo Be » Thu, 29 Aug 2002 17:24:47




>> > Why not just count the number of bytes you malloc?
>> I want to detect memory leaks in functions not written by myself.

> In that case, use one of the tools written for this purpose, such
> as mpatrol, dmalloc, ccmalloc, valgrind, Insure++ ...

Until now i have not looked at these tools, but i am not sure if they
work anyway in my case because the code i want to check is Java JNI code,
so i need to trace the whole java binary to get what i want.

However, i could always look at their code for how to do it, if there
are opensource projects. thanks for the hint.

-timo

 
 
 

memory monitoring

Post by Neil Horma » Thu, 29 Aug 2002 20:41:36



> Hi,

> I have got the following problem:

> I need a way to get the memory size used by my program.
> It should look like the following:

Thats a fairly vague question, as malloc does not necessecarily increase the
amount of memory allocated to a process.  Is it actual allocated memory you are
after, or allocated address space?

Quote:> ---<snip>---
> int mem = getUsedMemory();

> char * buffer = (char*)malloc(1024);

> mem = getUsedMemory(); // now mem should be 1024 bytes bigger
> ---<snap>-

> Is there already such e function or, if not, how can i implement
> it?

There is not such a function, but if you are interested, in /proc/<pid> where
<pid> is the proccess id number of your program, there is a file called status.
  In that file there are several lines prefixed with the characters "Vm"  These
values represent the amount of allocated address space a process has, if that
helps you at all.  You may be able to implement your function using these
values.  Mind, however, that they do not represent the amount of memory your
program is actually using.
Neil
Quote:

> Any pointers aprecciated,
> -timo

 
 
 

1. Sun workshop memory monitor does not detect all memory leak

Cud somebody tell me wat is happening???
I am checking if I can use Sun WorkShop Memory Monitor as a substitute for
Rational purify
but this simple leak is not detected.

#include <iostream.h>
int main()
{
int *name ;
name = new int[10];                                 <-------this is not
detected as leak
cout<< "name is "<<name[0] <<endl;
delete [] name;
return 0;

 On the other hand if i allocate memory in a loop like this it is detected
as a leak

#include <iostream.h>
int main()
{
int *name ;
/for (int i=0; i<3 ; i++)
    name = new int[10];                                 <-------this is
detected as leak
cout<< "name is "<<name[0] <<endl;
delete [] name;
return 0;

Is it safe to go ahead and use Sun WorkShop Memory Monitor instead of
purify?

2. power-save the monitor

3. physical memory monitor

4. KPaint won't save

5. Good memory monitoring tools!

6. EXT2 problem with linux 1.2.5

7. Memory Monitoring Utility.

8. Future Domain 1670 card query

9. Memory Monitoring

10. Question about virtual swap space and a memory monitor

11. Linux Memory Monitor

12. memory monitoring tool

13. Automated memory monitoring