malloc question
Knobi der Rechnerschrat
XBR2D96D at DDATHD21.BITNET
Fri Jan 19 05:47:01 AEST 1990
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: <XBR2D96D at DDATHD21>
--------------------------mt1.c------------------------------------------
/* compile using 'cc -O mt1.c -o mt1 -lmalloc' */
/* using the 'normal' malloc package gives the same results */
#include <stdio.h>
#include <malloc.h>
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-----------------------------------
More information about the Comp.sys.sgi
mailing list