Connecting Tech Pros Worldwide Forums | Help | Site Map

memory used by a process

mohi
Guest
 
Posts: n/a
#1: Jul 25 '08
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

santosh
Guest
 
Posts: n/a
#2: Jul 25 '08

re: memory used by a process


mohi wrote:
Quote:
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.
Quote:
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.

neobakuer
Guest
 
Posts: n/a
#3: Jul 25 '08

re: memory used by a process


On 25 jul, 13:18, mohi <mohangupt...@gmail.comwrote:
Quote:
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/
Quote:
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.
Antoninus Twink
Guest
 
Posts: n/a
#4: Jul 26 '08

re: memory used by a process


On 25 Jul 2008 at 20:53, santosh wrote:
Quote:
mohi wrote:
Quote:
>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.
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.hand 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."
Quote:
Quote:
>and what can be the possible reasons of an error like
>>
>glibc detected:malloc() memory corruption
As others have said, valgrind is just the thing for getting to the
bottom of problems like this.

Closed Thread