GlobalMemoryStatusEx系统内存信息

来源:互联网 发布:oracle数据库培训班 编辑:程序博客网 时间:2024/05/22 16:55
 GlobalMemoryStatusEx函数用于获取系统内存信息:

BOOL WINAPI GlobalMemoryStatusEx(
  __inout  LPMEMORYSTATUSEX lpBuffer
);

示例代码:

void CTestDlg::GetMemoryInfo()
{
 MEMORYSTATUSEX statex;

 statex.dwLength = sizeof (statex);

 GlobalMemoryStatusEx(&statex);

 CString strInfo = "内存:\r\n";
 CString strTemp = "";
 // 内存使用率
 strTemp.Format("There is  %ld percent of memory in use.\r\n", statex.dwMemoryLoad);
 strInfo += strTemp;
 // 物理内存
 strTemp.Format("There are %I64d total Kbytes of physical memory.\r\n", statex.ullTotalPhys/1024);
 strInfo += strTemp;
 // 可用物理内存
 strTemp.Format("There are %I64d free Kbytes of physical memory.\r\n", statex.ullAvailPhys/1024);
 strInfo += strTemp;
 // 认可用量:总数
 strTemp.Format("There are %I64d total Kbytes of paging file.\r\n", statex.ullTotalPageFile/1024);
 strInfo += strTemp;
 // 认可用量:未用
 strTemp.Format("There are %I64d free Kbytes of paging file.\r\n", statex.ullAvailPageFile/1024);
 strInfo += strTemp;
 // 虚拟内存
 strTemp.Format("There are %I64d total Kbytes of virtual memory.\r\n", statex.ullTotalVirtual/1024);
 strInfo += strTemp;
 // 可用虚拟内存
 strTemp.Format("There are %I64d free Kbytes of virtual memory.\r\n", statex.ullAvailVirtual/1024);
 strInfo += strTemp;
 // ullAvailExtendedVirtual保留字段
 strTemp.Format("There are %I64d free Kbytes of extended memory.\r\n", statex.ullAvailExtendedVirtual/1024);
 strInfo += strTemp;

 m_staticMemory.SetWindowText(strInfo);
}

运行结果: