以下程式片段示範了 Windows API: GlobalMemoryStatus 的用法:
//----------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMemoryStatus MemoryStatus;
MemoryStatus.dwLength = sizeof(MemoryStatus);
GlobalMemoryStatus(&MemoryStatus);
Label1->Caption = "Total Physical Memory: " +
IntToStr(MemoryStatus.dwTotalPhys);
}
MemoryStatus 結構:
typedef struct _MEMORYSTATUS { // mst
DWORD dwLength; // sizeof(MEMORYSTATUS)
DWORD dwMemoryLoad; // percent of memory in use
DWORD dwTotalPhys; // bytes of physical memory
DWORD dwAvailPhys; // free physical memory bytes
DWORD dwTotalPageFile; // bytes of paging file
DWORD dwAvailPageFile; // free bytes of paging file
DWORD dwTotalVirtual; // user bytes of address space
DWORD dwAvailVirtual; // free user bytes
} MEMORYSTATUS, *LPMEMORYSTATUS;
               (
geocities.com/huanlin_tsai)