Bagikan melalui


Fungsi GlobalMemoryStatusEx (sysinfoapi.h)

Mengambil informasi tentang penggunaan memori fisik dan virtual sistem saat ini.

Sintaks

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

Parameter

[in, out] lpBuffer

Penunjuk ke struktur MEMORYSTATUSEX yang menerima informasi tentang ketersediaan memori saat ini.

Nilai kembali

Jika fungsi berhasil, nilai yang dikembalikan bukan nol.

Jika fungsi gagal, nilai yang dikembalikan adalah nol. Untuk mendapatkan informasi kesalahan yang diperluas, hubungi GetLastError.

Keterangan

Anda dapat menggunakan fungsi GlobalMemoryStatusEx untuk menentukan berapa banyak memori yang dapat dialokasikan aplikasi Anda tanpa sangat memengaruhi aplikasi lain.

Informasi yang dikembalikan oleh fungsi GlobalMemoryStatusEx volatil. Tidak ada jaminan bahwa dua panggilan berurutan ke fungsi ini akan mengembalikan informasi yang sama.

Anggota ullAvailPhys dari struktur MEMORYSTATUSEX di lpBuffer menyertakan memori untuk semua simpul NUMA.

Contoh

Kode berikut menunjukkan penggunaan sederhana fungsi 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);
}

Persyaratan

Persyaratan Nilai
Klien minimum yang didukung Windows XP [aplikasi desktop | Aplikasi UWP]
Server minimum yang didukung Windows Server 2003 [aplikasi desktop | Aplikasi UWP]
Target Platform Windows
Header sysinfoapi.h (sertakan Windows.h)
Pustaka Kernel32.lib
DLL Kernel32.dll

Lihat juga

MEMORYSTATUSEX

Fungsi Manajemen Memori

Informasi Performa Memori

Ruang Alamat Virtual dan Penyimpanan Fisik