www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/15/00:43:31

From: "John M. Aldrich" <fighteer AT NO DOT SPAM DOT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Growing pains with DJGPP
Date: Mon, 14 Apr 1997 08:57:36 -0700
Organization: Two pounds of chaos and a pinch of salt
Message-ID: <335253F0.4F7D@NO.SPAM.cs.com>
References: <F0CA7778D3 AT fs2 DOT mt DOT umist DOT ac DOT uk>
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
Lines: 34
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Anthony.Appleyard wrote:
> 
>    As virtual memory is much slower than physical, how can a (program which
> keeps on malloc()'ing more store) find when it is starting to need to swop
> parts of its heap to disk? Someone told me that DPMI can't directly tell you
> how much physical RAM is stil free; but how can the program ask DPMI how much
> swopping has happened recently?

DPMI, as far as I know, has no option to directly determine if it is
swapping to or from disk.  It does, however, provide lots of internal
structures and values that you can look up, and it's possible that they
contain something that will be of use.  Look in the DPMI Overview in the
libc docs for details; I have neither the time nor the desire to perform
a detailed examination myself.  :)

There are, however, lots of indirect methods.  You could do something as
simple as call _go32_dpmi_remaining_physical_memory() and check to see
if it is at or near zero.  You can also attempt to lock all memory that
you allocate - when locking fails, you've run out of physical memory. 
Quake uses such a test when it boots.  You could even use the timing
functions to test the average speed of accessing a block of memory; if
it is much larger than the average it's probably being paged in.

The other thing about using malloc() is that it doesn't actually page in
the memory you allocate until it is accessed.  For a true test of how
long it will take you to access a memory block of a given size, use
calloc().

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT com      |
| Proud owner of what might one   |   http://www.cs.com/fighteer    |
| day be a spectacular MUD...     | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------

- Raw text -


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