Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucbvax!DDATHD21.BITNET!XBR2D96D From: XBR2D96D@DDATHD21.BITNET (Knobi der Rechnerschrat) Newsgroups: comp.sys.sgi Subject: malloc question Message-ID: <9001181348.aa27967@ADM.BRL.MIL> Date: 18 Jan 90 18:47:01 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 51 Hallo, I've just found a behaviour in a program, that I don't understand. When running the program mt1 (appended to this message) the value returned from sbrk(0) is only changed for the first malloc(...). In that case the difference between old and new break-value is the desired 4MB. In the remaining 9 loops, old and new break-value are the same, but as easily can be seen, in all 10 loops the same pointer is returned. How do I interpret this behaviour? Does it mean that free(...) frees the memory allocated by the process for future use, but does not return the virtual memory? I've written the test program, because we have a programm that does a lot of malloc/free calls and it seems its virtual memory (as shown by ps -l) never shrinks. It grows, but only when more memory is needed. Is this the normal behaviour, or is something wrong (e.g. my understanding of malloc/free and my interpretation of sbrk())? I hope somebody can shed some light on that. We are running a 4D-70/GT with 16 MB of memory, ESDI root-disk and SCSI Data-disk. Our IRIX is Release 3.2 (btw. when will 3.2.1 be shipped ?). Regards Martin Knoblauch TH-Darmstadt Physical Chemistry 1 Petersenstrasse 20 D-6100 Darmstadt, FRG BITNET: --------------------------mt1.c------------------------------------------ /* compile using 'cc -O mt1.c -o mt1 -lmalloc' */ /* using the 'normal' malloc package gives the same results */ #include #include main() { int i=0; char *sbrk(),*obrk,*nbrk,*dum; for(i=0;i<10;i++) { obrk = sbrk(0); dum = malloc(4000000); nbrk = sbrk(0); printf("Memtest: %x %x %x %d\n",dum,obrk,nbrk,nbrk-obrk); free(dum); } } --------------------------end of mt1.c-----------------------------------