[Gllug] mallinfo

t.clarke tim at seacon.co.uk
Tue Oct 30 11:42:43 UTC 2007


Help !!
Bit of expert C advice required  please

I need to be able to keep track of total memory allocated by malloc within a
particular program,  but is doesn't work :-(

The following 'test' program works on a Unix system correctly,
but on a LInux system (debian), it reports the final 'alloc' line
(after calling mallinfo) as ZERO  !!

I cannot for the life of me see what is wrong.

Any suggestions (or do I have a buggy glib ?)

Tim

----





#include <unistd.h>
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
main(argc, argv)
/*copy input file to output file omitting carriage-returns*/
int argc;
char *argv[];
{
unsigned long int b;
char *old_brk, *new_brk, *mema, *memb, *memc;
struct mallinfo mallinf;
mema=malloc(3200000);
printf("mema %ld\n",mema);
memb=malloc(3200000);
printf("memb %ld\n",memb);
memc=malloc(3200000);
printf("memc %ld\n",memc);
b=mema-memc;
printf("alloc %ld\n",b);
mallinf=mallinfo();
printf("alloc %ld\n",mallinf.arena);
}

--------------------------------------------------------------------------------
This E-Mail (and any files transmitted with it) is intended solely for the use
of the individual or entity to whom it is addressed. If you have received it in
error please notify the sender and delete the message.

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list