017 系統內存信息 內存大小 空閒內存 5

# 017 系統內存信息 內存大小 空閒內存 5windows

  GetSystemInfo 函數
    函數原型:函數

1 void WINAPI GetSystemInfo( _Out_ LPSYSTEM_INFO lpSystemInfo);

 

      參數1:lpSystemInfo [out]
      返回一個 SYSTEM_INFO 結構體指針信息

  結構體原型:spa

 1 typedef struct _SYSTEM_INFO {
 2     union {
 3         DWORD  dwOemId;
 4         struct {
 5                 WORD wProcessorArchitecture;
 6                   WORD wReserved;
 7         };
 8   };
 9     DWORD     dwPageSize;
10     LPVOID    lpMinimumApplicationAddress;
11     LPVOID    lpMaximumApplicationAddress;
12     DWORD_PTR dwActiveProcessorMask;
13     DWORD     dwNumberOfProcessors;
14     DWORD     dwProcessorType;
15     DWORD     dwAllocationGranularity;
16     WORD      wProcessorLevel;
17     WORD      wProcessorRevision;
18 } SYSTEM_INFO;

 

  SYSTEM_INFO結構體參數說明:
    wProcessorArchitecture: Word; {處理器的體系結構}
    wReserved: Word;  {保留}
    dwPageSize: DWORD;  {分頁大小}
    lpMinimumApplicationAddress: Pointer;{最小尋址空間}
    lpMaximumApplicationAddress: Pointer;{最大尋址空間}
    dwActiveProcessorMask: DWORD; {處理器掩碼; 0..31 表示不一樣的處理器}
    dwNumberOfProcessors: DWORD;  {處理器數目}
    dwProcessorType: DWORD; {處理器類型}
    dwAllocationGranularity: DWORD; {虛擬內存空間的粒度}
    wProcessorLevel: Word;  {處理器等級}
    wProcessorRevision: Word);  {處理器版本}指針

 

  GlobalMemoryStatus 函數
    Win32 API函數。 此函數用來得到當前可用的物理和虛擬內存信息

    函數原型:code

1 void WINAPI GlobalMemoryStatus(_Out_ LPMEMORYSTATUS lpBuffer);


  參數1:lpBuffer [out]
    返回一個 lpBuffer MEMORYSTATUS 結構體
blog

 

 1 typedef struct _MEMORYSTATUS { 
 2     DWORD dwLength;                         // MEMORYSTATUS結構的大小
 3     DWORD dwMemoryLoad;                 // 返回一個介於0~100之間的值,用來指示當前系統內存的使用率
 4     DWORD dwTotalPhys;                     // 返回總的物理內存大小,以字節(byte)爲單位。
 5     DWORD dwAvailPhys;                     // 返回可用的物理內存大小,以字節(byte)爲單位。
 6     DWORD dwTotalPageFile;                 // 顯示能夠存在頁面文件中的字節數。注意這個數值並不表示在頁面文件在磁盤上的真實物理大小。
 7     DWORD dwAvailPageFile;                 // 返回可用的頁面文件大小,以字節(byte)爲單位。
 8     DWORD dwTotalVirtual;                     // 返回調用進程的用戶模式部分的所有可用虛擬地址空間,以字節(byte)爲單位。
 9     DWORD dwAvailVirtual;                     // 返回調用進程的用戶模式部分的實際自由可用的虛擬地址空間,以字節(byte)爲單位。
10 } MEMORYSTATUS, *LPMEMORYSTATUS;

 

 

 1 #define UNICODE
 2 #include <windows.h>
 3 #include <stdio.h>
 4 
 5 int main()
 6 {
 7     SYSTEM_INFO sysInfo;
 8     GetSystemInfo(&sysInfo);
 9     printf("頁面大小:%d\r\n",sysInfo.dwPageSize);
10     printf("分配顆粒:%d\r\n",sysInfo.dwAllocationGranularity);
11     printf("用戶區開始地址:0x%d\r\n",sysInfo.lpMinimumApplicationAddress);
12     printf("用戶最大地址:0x%d\r\n",sysInfo.lpMaximumApplicationAddress);
13     
14     MEMORYSTATUS memStatus;
15     GlobalMemoryStatus(&memStatus);
16     
17     printf("使用比:%d%%\r\n", memStatus.dwMemoryLoad);
18     printf("總內存大小:%x%%\r\n", memStatus.dwTotalPhys);
19     printf("可內存大小:%x%%\r\n", memStatus.dwAvailPhys);
20     return 0;
21 }

相關文章
相關標籤/搜索