* Funny thing whith malloc/free...
@ 1996-11-11 14:19 Daniel Hirschberg
1996-11-11 14:38 ` Jim Nance
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Hirschberg @ 1996-11-11 14:19 UTC (permalink / raw)
Hi there,
I've got a funny story and a question regarding malloc and free!
First the history... A friend of mine was playing with solaris and AIX
with a little program of his that asks for memory with malloc, sleeps a
little, then frees it and sleeps another time and starts over getting
memory. The sleeps were quite long so he could see the process grow
and shrink (hopefully) using ps.
We found out that the process size reported by ps never went
down... It did not increase when the size asked for was smaller than the
freed space (so free was working OK), but the process never shrunk!
So I told him, "let's try it on my linux, you know, a good os...",
and here comes the funny thing we found:
the process does grow and shrink as expected with many requests
of different sizes, but when it requests about 6 megs it gets them, but
never shrunk again.
Now the question, is this a feature ? am I losing something ?
Best regards,
daniel.
PS1: the source code is included at the end!
PS2: I tried it on a 1.3.18 kernel, but a friend tried on a 2.0.20 (I
think), with the same results!
PS3: I have not tried it on an intel box so I down't know if it's axp
related or not.
--
daniel@ing.puc.cl
--><--
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
main()
{
int j;
char *p;
int factor[6] ={1,4,3,12,3,2};
char test[4*1024];
printf("Inicio de prueba\n");
sleep(10);
for (j=0; j<6; j++)
{
p=(char *)calloc(factor[j]*150,sizeof(test));
sprintf(p, "%d*512K de memoria conseguido con calloc", factor[j]);
printf("-->%s\n",p);
printf("%s\n", p);
sleep(5);
free(p);
printf("memoria liberada\n");
sleep(10);
}
printf("Fin de prueba\n");
sleep(10);
}
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Funny thing whith malloc/free...
1996-11-11 14:19 Funny thing whith malloc/free Daniel Hirschberg
@ 1996-11-11 14:38 ` Jim Nance
0 siblings, 0 replies; 2+ messages in thread
From: Jim Nance @ 1996-11-11 14:38 UTC (permalink / raw)
> We found out that the process size reported by ps never went
> down... It did not increase when the size asked for was smaller than the
> freed space (so free was working OK), but the process never shrunk!
This is the way most implementations of malloc and free work. When you free
memory, it goes into a free pool, but it is not returned to the OS. This
behavior is dependent on the implementation of malloc() and free(). It
is not forced either way by the kernel.
Jim
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-11-11 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-11-11 14:19 Funny thing whith malloc/free Daniel Hirschberg
1996-11-11 14:38 ` Jim Nance
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox