delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/16/21:54:59

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.games.development.programming.misc
Subject: Re: Compacting the Memory
Date: Mon, 16 Aug 1999 11:15:01 -0700
Organization: Alcyone Systems
Lines: 39
Message-ID: <37B85525.D1AF391D@alcyone.com>
References: <7p974q$4gg$1 AT news6 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.0.34 i686)
X-Accept-Language: en, eo
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ben Davis wrote:

> I am writing a program in DJGPP C, which uses the memory VERY
> dynamically:
> there are loads of malloc()s and free()s. They occur in a strange
> order, and
> some are quite large. If two blocks are allocated, and then the first
> one is
> freed, and then a third, larger block is allocated before the second
> one is
> freed, some memory is wasted (I fear).

It'll only get wasted if you don't free up those blocks of memory. 
Under ANSI C (so this includes DJGPP), the memory allocator simply
allocates blocks of memory, and then reuses memory from the free store
when it gets the opportunity.

> What I would like to know is, does DJGPP automatically compact the
> memory by
> moving blocks down to fill all the gaps, or do I have to do it
> manually? How
> can I do this?

You'll have to do it yourself.  There's no way under ANSI C to do this,
since by definition if you were to move the blocks of memory around to
compact the heap, then your pointers to this memory would now be
invalid.

Before you embark on such an undertaking, though, you should first see
whether or not it is really necessary.

-- 
Erik Max Francis | icq 16063900 | whois mf303 | email max AT alcyone DOT com
 Alcyone Systems | irc maxxon (efnet) | web http://www.alcyone.com/max/
    San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
             USA | Mon 1999 Aug 16 (14%/948) | &tSftDotIotE
 __
/  \ Said it? yep / Regret it? nope
\__/ Ice Cube

- Raw text -


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