delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/31/03:39:14

Date: Fri, 30 Jan 1998 22:40:33 -0800 (PST)
Message-Id: <199801310640.WAA09921@adit.ap.net>
Mime-Version: 1.0
To: lubaldo AT adinet DOT com DOT uy, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Physical memory, virtual memory. DJGPP+CWSDPMI, how they
work?

At 08:37  1/30/1998 -0300, lubaldo AT adinet DOT com DOT uy wrote:
>	Hello everyone! I think this is on-topic... if it is not... sorry.
>
>	I would like to know how physical memory and virtual memory works using
>CWSDPMI and DJGPP. I want to know this only for curiosity... but maybe this
>helps someone or someone has the same curiosity...
>
>	Suppose I have a computer with 2 mb free of memory, DOS 6.22 and CWSDPMI
>as DPMI provider. Suppose I have a program (compiled with DJGPP) that it
>has 1mb of code and 2mb of music and bitmaps. Ok, this are my questions:
>
>	1- Suppose I load all the program and the music and the bitmaps on the
>startup. Then, I use only 1mb of the music and the bitmaps in a first
>stage, so the 2mb of the free memory are full with 1mb of code and 1mb of
>data. The question is: what happens when the program enters in a 2nd stage
>where I use the same 1mb of code but the other 1mb of the data?
>		- The previous data is stored in virtual memory and the other data (the
>one that it is used now and has not been used before) is loaded in memory?
>		- The previous data is leaved in memory and the other (new) data is
>readed from virtual memory?
I'm not sure which of these cases more closely fits reality. I'll try to
explain it as best I can.

CWSDPMI, or whatever DPMI server you use, implements virtual memory. This
uses the 386's paging mechanism. Some 4K pages in your program's address
space are `present', and correspond to an actual chunk of physical memory.
Others are `not present'. When you try to access them, the CPU generates a
`page fault' and the DPMI server sees this, loads the page you want from
disk, sets that page to point to the right place in memory, and resumes your
program.
Now. The startup code loads the entire executable image into virtual memory
(I'm fairly sure no demand-loading). If some of it does not fit, it will be
paged to disk immediately. When you touch it, it will be paged in, and the
DPMI server will have to pick some other page to swap out to make room for
it. One common policy used to pick this is LRU: The Least Recently Used page
is swapped out.
>
>	2- CWSDPMI or DJGPP has something to optimize the speed when all the
>physical memory is not suficient to hold all the data (something like a
>cache?)?
Not that I know of, unless I misunderstand you. When it needs to read or
write a page that doesn't fit in memory, it has to be brought in and some
other page taken out. If you have a disk cache, that will affect the
swapping (since it is a disk write), but it sort of defeats the purpose in
that if the memory you use for a disk cache were free, you might not need to
swap in the first place.
Note that I'm not advising you not to use a disk cache. It will speed up all
other disk I/O and you should use it unless memory is very tight.
>
>	When I say virtual memory I am saying the memory that it is simulated
>using the harddisk.
>	I hope I was clear, because is difficult to me write in English.
>	Ok, TIA and goodbye!

Hope this helps

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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