www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/10/12/12:32:08

Date: Tue, 12 Oct 93 16:23:46 +0100
From: fabio AT kandinsky DOT usr DOT dsi DOT unimi DOT it (Fabio Pistolesi)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Malloc and free

 
> >     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.
> 
>


I noticed the same problem with 2.4.1 and if you watch at debug32 memory numbers
on top of screen you can see how malloc/free change the memory.

Fabio 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019