malloc pb

Yann Collete collette@clt13bi.der.edf.fr
Thu Jul 12 01:08:00 GMT 2001


Hello,

I've a little problem with malloc (maybe a bug).

I wrote the little following program:

#include <stdlib.h>
#include <time.h>

int main()
{
  char * PtrChar;
  time_t tstart, tend;
  
  PtrChar = (char *)malloc(1000000*sizeof(char));
  time(&tstart);
  while(difftime(time(&tend), tstart) < 60) ;
  free(PtrChar);
  PtrChar = (char *)malloc(10000*sizeof(char));
  time(&tsart);
  while(difftime(time(&tend), tstart) < 60) ;
  free(PtrChar);
}

I use the "top" program to follow the evolution of the memory
(the SHARE, RSS and SIZE label).
For the first malloc, I've SIZE=RSS=296ko and SHARE=240ko.
For the second malloc, I've SIZE=RSS=300ko and SHARE=240ko.

The memory doesn't seems to decrease between to two mallocs.
Why does it behave like this ?
the man page of top doesn't indicate that SIZE, RSS, SHARE measure
the max of the memory during the whole time of the process.

Yann COLLETTE



More information about the Gcc-help mailing list