本文为个人使用后的一些总结,逐步完善中...
1、获得全局内存
对应函数:void GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer); 【总内存2G以内使用】
API:
typedef struct _MEMORYSTATUS { DWORD dwLength; //本结构的长度; DWORD dwMemoryLoad; //已用内存的百分比; SIZE_T dwTotalPhys; //物理内存总量; SIZE_T dwAvailPhys; //可用物理内存; SIZE_T dwTotalPageFile; //交换文件总的大小; SIZE_T dwAvailPageFile; //交换文件中空闲部分大小; SIZE_T dwTotalVirtual; //用户可用的地址空间; SIZE_T dwAvailVirtual; //当前空闲的地址空间; } MEMORYSTATUS, *LPMEMORYSTATUS;
使用实例:
void CGetMemory_1Dlg::OnBnClickedButton1() { MEMORYSTATUS lpBuffer; lpBuffer.dwLength = sizeof(MEMORYSTATUS); GlobalMemoryStatus(&lpBuffer); }
【总内存2G~4G的建议使用扩展函数】GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
API:
typedef struct _MEMORYSTATUSEX { DWORD dwLength; DWORD dwMemoryLoad; DWORDLONG ullTotalPhys; DWORDLONG ullAvailPhys; DWORDLONG ullTotalPageFile; DWORDLONG ullAvailPageFile; DWORDLONG ullTotalVirtual; DWORDLONG ullAvailVirtual; DWORDLONG ullAvailExtendedVirtual; } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
使用实例:
void CGetMemory_1Dlg::OnBnClickedButton1() { MEMORYSTATUSEX lpBuffer; lpBuffer.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&lpBuffer); }
2、获得取得某一进程内存
call:
BOOL GetProcessMemoryInfo(
HANDLE Process,
PPROCESS_MEMORY_COUNTERS ppsmemCounters,
DWORD cb
);
API:
typedef struct _PROCESS_MEMORY_COUNTERS { DWORD cb; DWORD PageFaultCount; SIZE_T PeakWorkingSetSize; SIZE_T WorkingSetSize; SIZE_T QuotaPeakPagedPoolUsage; SIZE_T QuotaPagedPoolUsage; SIZE_T QuotaPeakNonPagedPoolUsage; SIZE_T QuotaNonPagedPoolUsage; SIZE_T PagefileUsage; SIZE_T PeakPagefileUsage; } PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS;
时间: 2024-10-28 14:11:52