GlobalMemoryStatusEx 함수(sysinfoapi.h)

물리적 메모리와 가상 메모리 모두에 대한 시스템의 현재 사용량에 대한 정보를 검색합니다.

구문

BOOL GlobalMemoryStatusEx(
  [in, out] LPMEMORYSTATUSEX lpBuffer
);

매개 변수

[in, out] lpBuffer

현재 메모리 가용성에 대한 정보를 수신하는 MEMORYSTATUSEX 구조체에 대한 포인터입니다.

반환 값

함수가 성공하면 반환 값이 0이 아닙니다.

함수가 실패하면 반환 값은 0입니다. 확장 오류 정보를 가져오려면 GetLastError를 호출합니다.

설명

GlobalMemoryStatusEx 함수를 사용하여 다른 애플리케이션에 심각한 영향을 주지 않고 애플리케이션이 할당할 수 있는 메모리 양을 결정할 수 있습니다.

GlobalMemoryStatusEx 함수에서 반환되는 정보는 휘발성입니다. 이 함수에 대한 두 개의 순차 호출이 동일한 정보를 반환한다는 보장은 없습니다.

lpBufferMEMORYSTATUSEX 구조체의 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

참고 항목

MEMORYSTATUSEX

메모리 관리 함수

메모리 성능 정보

가상 주소 공간 및 물리적 스토리지