cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/16/17:14:11

From: REMOVE_ericleif AT mindspring DOT com (eric)
Newsgroups: comp.os.msdos.djgpp,comp.games.development.programming.misc
Subject: Re: Compacting the Memory
Date: Mon, 16 Aug 1999 11:27:43 -0400
Organization: none
Lines: 44
Message-ID: <MPG.1221f7fcc1bd2c19989793@news.mindspring.com>
References: <7p974q$4gg$1 AT news6 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: d1.8a.1a.09
X-Server-Date: 16 Aug 1999 15:26:49 GMT
X-Newsreader: MicroPlanet Gravity v2.10.940
X-No-Archive: yes
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <7p974q$4gg$1 AT news6 DOT svr DOT pol DOT co DOT uk>, 
ben AT vjpoole DOT freeserve DOT co DOT uk says...
> 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.

You might consider controlling the memory management yourself. Or use 
less dynamic algorithms.

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

You'll have to explain your reasoning about this memory wasting, I'm not 
sure I follow you. I also don't think any memory is wasted. And by large 
block how much are you talking about here 2M, 200M ?

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

No, yes. However I see no problem with having gaps, thats all under the 
control of the memory manager or the OS, since you are using malloc. If 
its performance you are worried about, you'd do better to first look at 
your code.

> How
> can I do this?

1. Use non-dynamic algorithms, there's nothing wrong with using a large 
array of structs (like say 1000 or more) and then just reusing that, 
perhaps even using a variable within the struct such as 'int inuse'. This 
is especially useful if you have some entities that come and go like most 
games do, whether they are explosions, or enemy space invaders.

2. Create a memory manager that knows what your program is generally 
going to do with the memory. It could be something as simple as a 
function that just tries to allocate as much memory as it can and then 
dole that out to where ever you are needing the memory. In general I 
don't see the problem with having gaps between different memory sequences 
as you seem to be leading to, especially if these are large blocks since 
more than likely going from one to the other is a cache miss no matter 
what you want to do.


- Raw text -


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