www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/26/23:51:54

Subject: Re: topline
To: OKRA AT max DOT tiac DOT net
Date: Sun, 26 Feb 1995 22:28:21 -0600 (CST)
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
From: mcastle AT umr DOT edu (Mike Castle)

Amazingly enough Kimberley Burchett said:
>   Is it me or is topline not updated when I free something?

Calling free() does not guarantee that memory is returned to the
system.  Just that it's returned to the pool of memory available
for reuse by malloc().  When malloc() et al need more memory,
they call brk()/sbrk() to obtain more core.  The ONLY time it is
even possible for the malloc package to return core to the system
is if the END of memory has been freed.  For example, if you do
something like:

a=malloc(100000);
b=malloc(100000);
c=malloc(100000);
d=malloc(1);
free(a);
free(b);
free(c);

Given a simple implementation (that is, assuming each call to
malloc() had to call sbrk() to obtain more core, and in order),
the memory is not even eligible to be returned until "d" is
freed.

It requires a fairly sophisticated malloc package to keep track
of all this.  

I don't believe the standard malloc package (BSD one?) that djgpp
comes with is that sophisticated.  After all, such a complex
malloc package will take up more code space, etc.  The GNU malloc
package will call sbrk as appropriate, then your code is GPLed
though.  

Your choice.

mrc
-- 
Mike Castle .-=NEXUS=-.  Life is like a clock:  You can work constantly
  mcastle AT cs DOT umr DOT edu     and be right all the time, or not work at all
   mcastle AT umr DOT edu       and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen

- Raw text -


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