Mail Archives: djgpp/1998/05/18/18:46:55
John Kismul wrote:
>
> How do I find out how much memory is available, NOT counting virtual
> memory ONLY physical memory.
It's a somewhat inexact process, but I can supply you with the code I use
for that purpose in my DJVERIFY program (thanks to Eli Zaretskii for the
original). This code detects up to 64 MB of installed RAM and returns the
amount in bytes. There are some caveats:
- The amount reported is usually about 300K off due to ROM BIOS shadowing.
- The value wraps around on machines with more than 64 MB of RAM.
- Windows NT may report less memory than is actually installed.
Good luck!
/*
* Routines to return the amount of physical memory installed on the host
* computer. Thanks to Eli Zaretskii for this code.
*/
static void usec_sleep( int usec )
{
uclock_t start_time = uclock ();
uclock_t end_time = start_time + UMAX(1, usec * UCLOCKS_PER_SEC / 1000000);
while ( uclock () < end_time )
;
}
static unsigned char read_cmos( int reg )
{
unsigned char al = ( reg & 0xff ) | 0x80; /* disable NMI */
outportb( 0x70, al );
usec_sleep( 2 ); /* delay for 2 microseconds */
al = inportb( 0x71 );
usec_sleep( 2 );
outportb( 0x70, 0 ); /* enable NMI */
return al;
}
int installed_memory_size( void )
{
unsigned base_lo, base_hi, ext_lo, ext_hi;
base_lo = read_cmos( 0x15 );
base_hi = read_cmos( 0x16 );
ext_lo = read_cmos( 0x17 );
ext_hi = read_cmos( 0x18 );
return ( (base_hi + ext_hi) << 8 ) + base_lo + ext_lo;
}
--
---------------------------------------------------------------------
| John M. Aldrich | "Sex should be friendly. Otherwise |
| aka Fighteer I | stick to mechanical toys; it's more |
| mailto:fighteer AT cs DOT com | sanitary." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -