Mail Archives: djgpp/1993/10/12/09:31:56
> I have made a small program which is supposed to alloc
> and free memory. The problem is that it dosen't free
> the allocated memory at all.
> #include <stdio.h>
> #include <malloc.h>
> void main ()
> {
> int c;
> void *p;
> c=0;
> while (c<800)
> {
> printf ("malloc: %d bytes \n",c*10000);
> p=malloc (c*10000);
> memset (p,0xff,c*10000);
> free (p);
> getch ();
> c+=100;
> }
> }
> I compile the program using: gcc prog.c -Wall
> Why is'nt the memory free'd ?
How do you know it isn't freed? There are no calls in there to check
memory status. Note that since you allocate ever-increasing block
sizes, the smaller chunks are never available for future mallocs. You
end up with a very large free list (djgpp's malloc doesn't merge free
blocks, sadly).
Try running your test the other way - start with big packets, then
allocate ever smaller ones.
- Raw text -