searching a function of standard libraries to help detecting memory leaks

D

Diego Martins

Hi all! I am doing a crude investigation of memory leaks in objects
created by external libraries.
Since I don't have access to the source code, I can't tell if an object
are freeing its resources properly during destruction.

For now, I need a portable function that can tell me the available free
store memory. With that, I can do things like:

size_t mem = getFreeStoreAvailable();
{
SuspiciousObject obj;
...
} // obj destructor invoked here by compiler

assert( mem == getFreeStoreAvailable() );


of course it won't work for detecting resource leaks (e.g: handles)

do you know this function? any ideas?

Diego Martins
HP
 
V

Victor Bazarov

Diego said:
Hi all! I am doing a crude investigation of memory leaks in objects
created by external libraries.

Welcome to the club!
Since I don't have access to the source code, I can't tell if an
object are freeing its resources properly during destruction.

For now, I need a portable function that can tell me the available
free store memory.

There is no such standard function. You either need to write your own,
or use whatever mechanism your OS provides.
With that, I can do things like:

size_t mem = getFreeStoreAvailable();
{
SuspiciousObject obj;
...
} // obj destructor invoked here by compiler

assert( mem == getFreeStoreAvailable() );


of course it won't work for detecting resource leaks (e.g: handles)

No such thing in standard C++.
do you know this function? any ideas?

No such standard function. Try the newsgroup for your OS.

Generally speaking, you _could_ measure it by allocating [in a loop]
different amounts until you get a failure, followed by freeing all that
you just allocated. However, that is not necessarily the true measure
of the "available free store memory". Remember the "you change it if
you measure it" principle? Ultimately, even if you have to call some
function to measure the free store memory, you *could* change it, and
the behaviour of the program *might* be different from if you didn't
ask for the avaiable free store memory.

V
 
J

Jacek Dziedzic

Diego said:
Hi all! I am doing a crude investigation of memory leaks in objects
created by external libraries.
Since I don't have access to the source code, I can't tell if an object
are freeing its resources properly during destruction.

For now, I need a portable function that can tell me the available free
store memory. With that, I can do things like:

size_t mem = getFreeStoreAvailable();
{
SuspiciousObject obj;
...
} // obj destructor invoked here by compiler

assert( mem == getFreeStoreAvailable() );


of course it won't work for detecting resource leaks (e.g: handles)

do you know this function? any ideas?

<OT>
If you are working on a x86 I suggest using valgrind.
It will detect memory leaks without the need to recompile
(although you may wish to recompile with -g to obtain
line-number information).
</OT>

HTH,
- J.
 

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
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top