GlobalMemoryStatusEx 函式 (sysinfoapi.h)
擷取系統目前使用實體和虛擬記憶體的相關信息。
語法
BOOL GlobalMemoryStatusEx(
[in, out] LPMEMORYSTATUSEX lpBuffer
);
參數
[in, out] lpBuffer
MEMORYSTATUSEX 結構的指標,可接收目前記憶體可用性的相關信息。
傳回值
如果函式成功,則傳回非零的值。
如果此函式失敗,則傳回值為零。 若要取得擴充的錯誤資訊,請呼叫 GetLastError。
備註
您可以使用 GlobalMemoryStatusEx 函 式來判斷應用程式可以配置的記憶體數量,而不會影響其他應用程式。
GlobalMemoryStatusEx 函式傳回的資訊是 volatile。 不保證此函式的兩個循序呼叫會傳回相同的資訊。
lpBuffer之 MEMORYSTATUSEX 結構的 ullAvailPhys 成員包含所有 NUMA 節點的記憶體。
範例
下列程式代碼顯示 GlobalMemoryStatusEx 函式的簡單用法。
// Sample output:
// There is 51 percent of memory in use.
// There are 2029968 total KB of physical memory.
// There are 987388 free KB of physical memory.
// There are 3884620 total KB of paging file.
// There are 2799776 free KB of paging file.
// There are 2097024 total KB of virtual memory.
// There are 2084876 free KB of virtual memory.
// There are 0 free KB of extended memory.
#include <windows.h>
#include <stdio.h>
#include <tchar.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 _tmain()
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
_tprintf (TEXT("There is %*ld percent of memory in use.\n"),
WIDTH, statex.dwMemoryLoad);
_tprintf (TEXT("There are %*I64d total KB of physical memory.\n"),
WIDTH, statex.ullTotalPhys/DIV);
_tprintf (TEXT("There are %*I64d free KB of physical memory.\n"),
WIDTH, statex.ullAvailPhys/DIV);
_tprintf (TEXT("There are %*I64d total KB of paging file.\n"),
WIDTH, statex.ullTotalPageFile/DIV);
_tprintf (TEXT("There are %*I64d free KB of paging file.\n"),
WIDTH, statex.ullAvailPageFile/DIV);
_tprintf (TEXT("There are %*I64d total KB of virtual memory.\n"),
WIDTH, statex.ullTotalVirtual/DIV);
_tprintf (TEXT("There are %*I64d free KB of virtual memory.\n"),
WIDTH, statex.ullAvailVirtual/DIV);
// Show the amount of extended memory available.
_tprintf (TEXT("There are %*I64d free KB of extended memory.\n"),
WIDTH, statex.ullAvailExtendedVirtual/DIV);
}
規格需求
需求 | 值 |
---|---|
最低支援的用戶端 | Windows XP [傳統型應用程式 |UWP 應用程式] |
最低支援的伺服器 | Windows Server 2003 [傳統型應用程式 |UWP 應用程式] |
目標平台 | Windows |
標頭 | sysinfoapi.h (包含 Windows.h) |
程式庫 | Kernel32.lib |
DLL | Kernel32.dll |