in reply to Using Perl to detect RAM amount

This script does the job on Win32.

#! perl -slw use Win32::API::Prototype; my $memoryStatus = AllocMemory( 32 ); ApiLink( 'Kernel32', 'GlobalMemoryStatus', 'P', 'V' ); GlobalMemoryStatus( $memoryStatus ); my @keys = qw[ length PercentageLoad TotalPhysical AvailablePhysical TotalPaged AvailablePaged TotalVirtualMemory AvailableVirtualMemory ]; my %mStatus; @mStatus{ @keys } = unpack 'V8', $memoryStatus; printf '%30s : %.2f' . $/, $_, $mStatus{ $_ } / 2**20 for @keys[1 .. $#keys ]; __END__ P:\test>gmem PercentageLoad : 0.00 TotalPhysical : 223.24 AvailablePhysical : 54.38 TotalPaged : 408.66 AvailablePaged : 228.52 TotalVirtualMemory : 2047.88 AvailableVirtualMemory : 2019.03

The TotalPhysical is the one you need. There have been several threads on doing this on various flavours of *nix.

With respect to putting the two on a floppy disc, you might get away with miniperl.exe (5.6.2 ~= 700k) from the source distribution. You would have to copy a few dependancies Config, Dynaloader, Autoloader, Win32::API::Prototype etc. including their binary components. The list isn't huge, however, that doesn't solve the dual boot problem.

But, given that the physical memory doesn't vary from OS to OS (unless you have RAM disks and stuff configured), you would probably be better off booting from a DOS floppy (assuming the hardware can run that) and use the DOS mem command (though that gives a weird mixture of real mode and protect mode numbers).

Or maybe a freeware DOS utility from somewhere. There used to be loads of things like that kicking around. It wouldn't work on non-DOSable hardware, but not much will.

Come to that, if you can boot into the bios configuration, the information ought to be available there.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re: Re: Using Perl to detect RAM amount
by Tommy (Chaplain) on Jan 06, 2004 at 02:54 UTC

    WOW! Impressive! Problem is, I can never get Win32::API to install on my machine, because I run C:\cywin\bin\perl.exe from within the cygwin environment, and generally shun the less portable/compatible-with-my-linux-development ActiveState Perl.

    But it's worth a shot. I'll definitely give this one a try! Thanks again, ++BrowserUk

    --
    Tommy Butler, a.k.a. TOMMY
    
      No, ActivePerl is far more portable and compatible with your Linux environment than cygwin is.

      Much as I like cygwin.


      --
      Regards,
      Helgi Briem
      hbriem AT simnet DOT is
Re: Re: Using Perl to detect RAM amount
by tachyon (Chancellor) on Jan 06, 2004 at 13:57 UTC

    This script does the job on Win32.

    So does this....

    C:\>perl -e "print `mem`" 655360 bytes total conventional memory 655360 bytes available to MS-DOS 633712 largest executable program size 1048576 bytes total contiguous extended memory 0 bytes available contiguous extended memory 941056 bytes available XMS memory MS-DOS resident in High Memory Area C:\>

    Actually the results or DOS mem are RUBBISH - Please Ignore this post...

    cheers

    tachyon