Mail Archives: djgpp/1997/04/15/00:43:31
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 -