刘收获

导航

GetSystemInfo 和 GlobalMemoryStatus获取系统信息,内存信息

// GetSystemInfo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
int main()
{
	SYSTEM_INFO systemInfo;
	GetSystemInfo(&systemInfo);
	cout << setw(20) << "处理器掩码: " << systemInfo.dwActiveProcessorMask << endl
		<< setw(20) << "处理器个数: " << systemInfo.dwNumberOfProcessors << endl
		<< setw(20) << "处理器分页大小: " << systemInfo.dwPageSize << endl
		<< setw(20) << "处理器类型: " << systemInfo.dwProcessorType << endl
		<< setw(20) << "最大寻址单元: " << systemInfo.lpMaximumApplicationAddress << endl
		<< setw(20) << "最小寻址单元: " << systemInfo.lpMinimumApplicationAddress << endl
		<< setw(20) << "处理器等级: " << systemInfo.wProcessorLevel << endl
		<< setw(20) << "处理器版本: " << systemInfo.wProcessorRevision << endl;
	return 0;
}

  

// GlobalMemoryStatus.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;


int main()
{
	MEMORYSTATUS ms;     //记录内容空间信息的结构体变量
	GlobalMemoryStatus(&ms);//调用GlobalMemoryStatus()函数获取内存信息
	cout << "total physical mem:" << (float)ms.dwTotalPhys / 1024 / 1024 << "MB" << endl;    //总的物理内存大小
	cout << "used physical mem:" << (float)(ms.dwTotalPhys - ms.dwAvailPhys) / 1024 / 1024 << "MB" << endl;  //已用物理内存大小
	cout << "avilible physical mem:" << (float)ms.dwAvailPhys / 1024 / 1024 << "MB" << endl;     //可用物理内存大小
	cout << endl;
	cout << "total Virtual mem:" << (float)ms.dwTotalVirtual / 1024 / 1024 << "MB" << endl;  //总的虚拟内存大小
	cout << "used Virtual mem:" << (float)(ms.dwTotalVirtual - ms.dwAvailVirtual) / 1024 / 1024 << "MB" << endl;   //已用虚拟内存大小
	cout << "avilible Virtual mem:" << (float)ms.dwAvailVirtual / 1024 / 1024 << "MB" << endl;   //可用虚拟内存大小
    return 0;
}

  

posted on 2017-12-22 16:06  沉疴  阅读(1522)  评论(0编辑  收藏  举报