Mail Archives: djgpp/1998/03/22/20:00:39
From: | "John M. Aldrich" <fighteer AT cs DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Allegro datfiles was:re: Compiler Optimizations
|
Date: | Sun, 22 Mar 1998 19:43:31 -0500
|
Organization: | Two pounds of chaos and a pinch of salt.
|
Lines: | 54
|
Message-ID: | <3515B033.52E3@cs.com>
|
References: | <0p4xE9q00WB_07il00 AT andrew DOT cmu DOT edu>
|
NNTP-Posting-Host: | ppp238.cs.com
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
James W Sager Iii wrote:
>
> The problem is that I'm kinda confused...
> My plan was to put all the images into one big file and only pull out a few out at a time to
> put in memory. Allegro will use the cwsdpmi thing to simulate ALOT of ram, but after a certain
> point(memory on chips are used, the hard drive is used and a noticable slow down occurs
> using memory. On my game, I malloc out a bunch of 40kb levels from one to a hundred or more...
> Malloc is weird in that it will only go up to the extended memory, and not hit the hard drive.
This is not quite true. A detailed explanation of how virtual memory
works would be fairly lengthy, but these are the basics:
- When you allocate memory using malloc(), virtual memory is obtained
from the DPMI host, but nothing actually changes on your computer. This
is why a statement such as:
char *p = malloc( 16 * 1024 * 1024 );
seems to execute instantly.
- Allocated memory is only paged in when it is accessed (read from or
written to). If you write:
for ( i = 0; i < 16 * 1024 * 1024; i++ )
p[1] = '\0';
your program will slow down as the hard drive is accessed.
- Memory is paged in 4K blocks. If you only use 4 megs of that space,
only those 4 megs will be paged in. The rest will float out there in
"limbo" until you use it.
> My questions are:
> A: If I load up 8 meg of images in a .dat file, and there is exactly 8 meg of
> extended memory: Will I be able to malloc out 4 meg of levels?
Yes, as long as you have enough disk space to use for virtual memory.
> B: If it doesn't crash, will the game be slowed down because it has to access the hard
> drive at unknown times because its using virtual memory?
It will not crash unless you don't have enough free disk space to store
anything that won't fit into physical memory. And it will be slowed
down if you access something that is currently paged out. cwsdpmi will
make some effort to help you with this by paging out the least
frequently used blocks of memory.
--
---------------------------------------------------------------------
| John M. Aldrich | "Animals can be driven crazy by pla- |
| aka Fighteer I | cing too many in too small a pen. |
| mailto:fighteer AT cs DOT com | Homo sapiens is the only animal that |
| http://www.cs.com/fighteer | voluntarily does this to himself." |
---------------------------------------------------------------------
- Raw text -