ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/17/14:50:51

Message-ID: <3CE53661.1F085892@yahoo.com>
Date: Fri, 17 May 2002 12:57:05 -0400
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Malloc/free DJGPP code
References: <10205161914 DOT AA17309 AT clio DOT rice DOT edu> <3CE41EB8 DOT 619484D9 AT yahoo DOT com> <9743-Fri17May2002100518+0300-eliz AT is DOT elta DOT co DOT il> <3CE4B60B DOT E68E28AB AT yahoo DOT com> <1225-Fri17May2002175128+0300-eliz AT is DOT elta DOT co DOT il>
Reply-To: djgpp-workers AT delorie DOT com

Eli Zaretskii wrote:
> > Date: Fri, 17 May 2002 03:49:31 -0400
> > From: CBFalconer <cbfalconer AT yahoo DOT com>
> > >
> > > Also, don't forget that there are other programs running on the same
> > > box, at least if you run on Windows.  So returning unused memory to
> > > the OS would be a Good Thing.
> >
> > The problem is that you can't return a complete block to the
> > system, because the internal allocation mechanism requires that
> > something always be left over.  Once the unexpected sbrk is
> > received the old block becomes completely available, and gets
> > used.  Forcing saving of a final piece would also be wasteful.
> Sorry, I don't understand what you mean.  Our sbrk allocates memory
> from the DPMI host in 64KB chunks.  Let's say that malloc has detected
> that a contiguous 64KB block at the top of the program's address space
> has been freed in its entirety, and calls sbrk to return that block
> to the DPMI host--what problems do you see with honoring that call?

The problem is in malloc.  It has to keep a lastsbrk block so as
to detect the expected/unexpected returns from sbrk.  Once it
returns a complete block that detect mechanism is lost.  In
nmalloc at least the lastsbrk pointer is initialized to NULL, and
it is assumed that that case signals that nothing is allocated
anywhere.  IIRC this is the same in the existing malloc code.

Returning a partial block, say the top half of a monster, should
not be a problem.

Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!

- Raw text -

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