This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

malloc pb


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]