The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Win32::SystemInfo - Memory and Processor information on Win32 systems

SYNOPSIS

    use Win32::SystemInfo;

# Get Memory Information

    my %mHash;
        if (Win32::SystemInfo::MemoryStatus(%mHash))
        {
         ...process results...
        }
         
        To get specific values: 
    my %mHash = (TotalPhys => 0, AvailPhys => 0);
        if (Win32::SystemInfo::MemoryStatus(%mHash))
        {
         ...mHash contains only TotalPhys and AvailPhys values...
        }
        
    Change the default return value:
        Win32::SystemInfo::MemoryStatus(%mHash,"MB");
        

# Get Processor Information

    my $proc = Win32::SystemInfo::ProcessorInfo();
        if ($proc >= 586) { ... }
        
        my %phash;
        Win32::SystemInfo::ProcessorInfo(%phash);
        for (my $i = 0; $i < $phash{NumProcessors}; $i++) {
         print "Speed of processor $i: " . $phash{"Processor$i"}{MHZ} . "MHz\n";
        }

ABSTRACT

With this module you can get total/free memory on Win32 systems, including installed RAM (physical memory) and page file. This module will also let you access processor information, including processor family (386,486,etc), speed, vendor, and revision information.

DESCRIPTION

    Module provides two functions:

    MemoryStatus

    Win32::SystemInfo::MemoryStatus(%mHash,[$format]);

       %mHash                      - The hash that will receive the results.
                                     Certain values can be set prior to the
                                     call to retrieve a subset. (See below)
       $format                     - Optional parameter. Used to set the order
                                     of magnitude of the results. (See below)
    
       Determines the current memory status of a Win32 machine. Populates
       %mHash with the results. Function returns undef on failure.
       
       Values returned through the hash:
       MemLoad                     - Windows NT 3.1 to 4.0: The percentage of
                                     approximately the last 1000 pages of physical
                                     memory that is in use.
                                   - Windows 2000: The approximate percentage of
                                     total physical memory that is in use.
       TotalPhys                   - Total amount of physical memory (RAM).
       AvailPhys                   - Available physical memory (RAM).
       TotalPage                   - Allocated size of page (swap) file.
       AvailPage                   - Available page file memory.
       TotalVirtual                - Total physical + maximum page file.
       AvailableVirtual            - Total amount of available memory.
       
       Values returned through the hash can also be specified by setting
       them before the function is called. 
           my %mHash = (TotalPhys => 0);
           Win32::MemoryInfo::MemoryStatus(%mHash);
             
       Will return only the total physical memory.
       
       MemoryStatus return values in bytes by default. This can be changed with
       the $format parameter. Valid values for $format are:
           B        -  Bytes (default)
           KB       -  Kilobytes
           MB       -  Megabytes
           GB       -  Gigabytes

    ProcessorInfo

    $proc = Win32::SystemInfo::ProcessorInfo([%pHash]);

       Determines the processor information of a Win32 computer. Returns a "quick"
       value or undef on failure. Can also populate %pHash with detailed information
       on all processors present in the system.
       
       $proc                        - Contains a numerical representation of the
                                    - processor level for Intel machines. For
                                    - example, a Pentium will return 586.
                                    - For non-Intel Windows NT systems, the
                                    - possible return values are:
                                    - PPC: PowerPC
                                    - MIPS: MIPS architecture
                                    - ALPHA: Alpha architecture
                                    - UNKNOWN: Unknown architecture
                                                                    
       %pHash                       - Optional parameter. Will be filled with 
                                    - information about all processors.
                                                    
       Values returned through hash:
       NumProcessors                - The number of processors installed
       ProcessorN                   - A hash containing all info for processor N
       
       Each ProcessorN hash contains the values:
       Identifier                   - The identifier string for the processor 
                                    - as found in the registry. The computer I'm
                                    - currently using returns the string
                                    - "x86 Family 6 Model 7 Stepping 3"
       VendorIdentifier             - The vendor name of the processor
       MHZ                          - The speed in MHz of the processor
                                    - Returns -1 if unable to determine.
                                          
       PLEASE read the note about the MHz value in Caveats, below.

No functions are exported.

INSTALLATION

Installation is simple. Follow these steps:

perl makefile.pl nmake nmake test nmake install

Copy the SystemInfo.html file into whatever directory you keep your documentation in. I haven't figured out yet how to automatically copy it over, sorry.

I've noticed that ActiveState can give an error about not being able to find perl when processing the makefile.pl file on Win9x. To get around this, open makefile.pl and add another key/value pair into WriteMakefile() that looks like this: 'PERL' => 'full/path/to/your/perl.exe', That should do the trick!

This module can also be used by simply placing it and the included DLL in your /Win32 directory somewhere in @INC.

This module requires Win32::API module by Aldo Calpini Win32::TieRegistry by Tye McQueen

CAVEATS

The information returned by the MemoryStatus function is volatile. There is no guarantee that two sequential calls to this function will return the same information.

On computers with more than 4 GB of memory, the MemoryStatus function can return incorrect information. Windows 2000 reports a value of -1 to indicate an overflow. Earlier versions of Windows NT report a value that is the real amount of memory, modulo 4 GB.

On Intel x86 computers with more than 2 GB and less than 4 GB of memory, the MemoryStatus function will always return 2 GB for TotalPhys. Similarly, if the total available memory is between 2 and 4 GB, AvailPhys will be rounded down to 2 GB.

ProcessorInfo will only reliably return CPU speed for Intel chips, and AMD chips that support the time stamp counter. (This appears to be K6-2, K6-III, all Athlons, and Duron.) The return value for MHz should always be checked in a Win9x environment to verify that it is valid. (Invalid processors, or other errors will return a -1.)

The ProcessorInfo function has been only tested in these environments: Windows 98, Single Pentium II processor Windows NT 4.0, Single Pentium III processor

All feedback on other configurations is greatly welcomed.

This module has been created and tested on Windows 98 and WinNT 4.0 on ActiveState port of Perl 5.6. It has not been tested on Windows 2000 yet.

CHANGES

 0.01 - Initial Release
 0.02 - Fixed CPU speed reporting for Win9x. Module now includes a DLL that
        performs the Win9x CPU speed determination.
 0.03 - Fixed warning "use of uninitialized value" when calling MemoryInfo
        with no size argument.

BUGS

Please report.

VERSION

This man page documents Win32::SystemInfo version 0.03

January 12, 2001.

AUTHOR

Chad Johnston <cjohnston@rockstardevelopment.com>

COPYRIGHT

Copyright (C) 2001 by Chad Johnston. All rights reserved.

LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1).

Win32 Win32/Utilities

1 POD Error

The following errors were encountered while parsing the POD:

Around line 209:

You can't have =items (as at line 213) unless the first thing after the =over is an =item