DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: get physical mem size and system resource

  1. #1
    zhouheng Guest

    get physical mem size and system resource


    Do you know how to get the size of available physical memory and resource
    usage percentage,just like those shown in the About box of C:\WINDOWS\EXPLORER.EXE,with
    windows API.

  2. #2
    Neil Schulman Guest

    Re: get physical mem size and system resource


    "zhouheng" <zhou_heng@yahoo.com> wrote:
    >
    >Do you know how to get the size of available physical memory and resource
    >usage percentage,just like those shown in the About box of C:\WINDOWS\EXPLORER.EXE,with
    >windows API.


    Use GlobalMemoryStatusEx to get physical memory. Here's Microsoft's sample
    of using it. I am not sure about the other.

    // Sample output:

    // c:\>globalex
    // 78 percent of memory is in use.
    // There are 65076 total Kbytes of physical memory.
    // There are 14248 free Kbytes of physical memory.
    // There are 150960 total Kbytes of paging file.
    // There are 88360 free Kbytes of paging file.
    // There are 1fff80 total Kbytes of virtual memory.
    // There are 1fe770 free Kbytes of virtual memory.
    // There are 0 free Kbytes of extended memory.

    #define _WIN32_WINNT 0x0500

    #include <windows.h>

    // Use to change the divisor from Kb to Mb.

    #define DIV 1024
    // #define DIV 1

    char *divisor = "K";
    // char *divisor = "";

    // Handle the width of the field in which to print numbers this way to
    // make changes easier. The asterisk in the print format specifier
    // "%*I64d" takes an int from the argument list, and uses it to pad
    // and right-justify the number being formatted.
    #define WIDTH 7

    void main(int argc, char *argv[])
    {
    MEMORYSTATUSEX statex;

    statex.dwLength = sizeof (statex);

    GlobalMemoryStatusEx (&statex);

    printf ("%ld percent of memory is in use.\n",
    statex.dwMemoryLoad);
    printf ("There are %*I64d total %sbytes of physical memory.\n",
    WIDTH, statex.ullTotalPhys/DIV, divisor);
    printf ("There are %*I64d free %sbytes of physical memory.\n",
    WIDTH, statex.ullAvailPhys/DIV, divisor);
    printf ("There are %*I64d total %sbytes of paging file.\n",
    WIDTH, statex.ullTotalPageFile/DIV, divisor);
    printf ("There are %*I64d free %sbytes of paging file.\n",
    WIDTH, statex.ullAvailPageFile/DIV, divisor);
    printf ("There are %*I64x total %sbytes of virtual memory.\n",
    WIDTH, statex.ullTotalVirtual/DIV, divisor);
    printf ("There are %*I64x free %sbytes of virtual memory.\n",
    WIDTH, statex.ullAvailVirtual/DIV, divisor);

    // Show the amount of extended memory available.

    printf ("There are %*I64x free %sbytes of extended memory.\n",
    WIDTH, statex.ullAvailExtendedVirtual/DIV, divisor);

    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center