Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
Memory Management
 GlobalMemoryStatusEx Function
GlobalMemoryStatusEx Function

Retrieves information about the system's current usage of both physical and virtual memory.

Syntax

BOOL WINAPI GlobalMemoryStatusEx(
  __inout  LPMEMORYSTATUSEX lpBuffer
);

Parameters

lpBuffer [in, out]

A pointer to a MEMORYSTATUSEX structure that receives information about current memory availability.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

You can use the GlobalMemoryStatusEx function to determine how much memory your application can allocate without severely impacting other applications.

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

The ullAvailPhys member of the MEMORYSTATUSEX structure at lpBuffer includes memory for all NUMA nodes. To get the available memory for a specific NUMA node, use the GetNumaAvailableMemoryNode function instead.

Windows 2000:  GetNumaAvailableMemoryNode is not supported.

Examples

The following code shows a simple use of the GlobalMemoryStatusEx function.

//  Sample output:
//  There is       51 percent of memory in use.
//  There are 2029968 total Kbytes of physical memory.
//  There are  987388 free Kbytes of physical memory.
//  There are 3884620 total Kbytes of paging file.
//  There are 2799776 free Kbytes of paging file.
//  There are 2097024 total Kbytes of virtual memory.
//  There are 2084876 free Kbytes of virtual memory.
//  There are       0 free Kbytes of extended memory.

#include <windows.h>
#include <stdio.h>

// Use to convert bytes to KB
#define DIV 1024

// Specify the width of the field in which to print the numbers. 
// The asterisk in the format specifier "%*I64d" takes an integer 
// argument and uses it to pad and right justify the number.
#define WIDTH 7

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

  statex.dwLength = sizeof (statex);

  GlobalMemoryStatusEx (&statex);

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

  // Show the amount of extended memory available.

  printf ("There are %*I64d free Kbytes of extended memory.\n",
          WIDTH, statex.ullAvailExtendedVirtual/DIV);
}

Requirements

ClientRequires Windows Vista, Windows XP, or Windows 2000 Professional.
ServerRequires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
HeaderDeclared in Winbase.h; include Windows.h.
LibraryUse Kernel32.lib.
DLLRequires Kernel32.dll.

See Also

GetNumaAvailableMemoryNode
Memory Management Functions
Memory Performance Information
MEMORYSTATUSEX
Virtual Address Space and Physical Storage


Send comments about this topic to Microsoft

Build date: 10/9/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker