memory used by a process

M

mohi

hello everyone ,
is there any cmmnd in gdb or any other way to find out whats the total
dynamically allocated memory
a process holds at various instances of execution???

and what can be the possible reasons of an error like

glibc detected:malloc() memory corruption

when the program executes almost the same function abt 2000 times with
no error
it does use dynamically alloted space and free it at every function
call

thank you very much
 
S

santosh

mohi said:
hello everyone ,
is there any cmmnd in gdb or any other way to find out whats the total
dynamically allocated memory
a process holds at various instances of execution???

You must keep track of this yourself, which you can do by means of
wrapping over malloc/realloc/calloc and free.
and what can be the possible reasons of an error like

glibc detected:malloc() memory corruption

when the program executes almost the same function abt 2000 times with
no error it does use dynamically alloted space and free it at every
function call

thank you very much

It means that the memory management function of your C library have
seemingly detected possible corruption of their internal data
structures. This could be due to a bug in your program (most likely) or
in your implementation (much less likely). The first thing to do is to
check whether you are writing past the bounds of any object in your
program. Secondly you need to check that you pass to free only those
values that you got with previous calls to malloc/realloc/calloc.

Something like Valgrind can do a lot of this automatically for you.
Compiling with bounds checking, if your compiler supports this, can
also help.
 
N

neobakuer

hello everyone ,
is there any cmmnd in gdb or any other way to find out whats the total
dynamically allocated memory
a process holds at various instances of execution???
use valgrind, start here http://cs.ecs.baylor.edu/~donahoo/tools/valgrind/
and what can be the possible reasons of an error like

glibc detected:malloc() memory corruption

when the program executes almost the same function abt 2000 times with
no error
it does use dynamically alloted space and free it at every function
call

thank you very much

probably you're writing outside the memory block allocated by malloc,
so is very probably that the problem is with your code, and not with
the implementation, use valgrind to check this.
 
A

Antoninus Twink

You must keep track of this yourself, which you can do by means of
wrapping over malloc/realloc/calloc and free.

Of course, it's quite likely that malloc will have some overhead, for
example by rounding up allocation requests to a size related to a power
of 2. So the process might "hold" more bytes than the total sum of the
sizes passed to successful malloc calls not yet freed.

As the OP seems to be using a GNU system, he could try #include
<malloc.h> and then use mallinfo() to fill in a struct mallinfo with
various pieces of information about the memory allocated in his process,
including an arena fields which gives "the total size of memory
allocated with sbrk by malloc, in bytes."

As others have said, valgrind is just the thing for getting to the
bottom of problems like this.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top