Windows获取物理内存的2种方式 - 随笔记录

  1 typedef enum _SYSTEM_INFORMATION_CLASS {
  2     SystemBasicInformation,
  3     SystemProcessorInformation,             // obsolete...delete
  4     SystemPerformanceInformation,
  5     SystemTimeOfDayInformation,
  6     SystemPathInformation,
  7     SystemProcessInformation,
  8     SystemCallCountInformation,
  9     SystemDeviceInformation,
 10     SystemProcessorPerformanceInformation,
 11     SystemFlagsInformation,
 12     SystemCallTimeInformation,
 13     SystemModuleInformation,
 14     SystemLocksInformation,
 15     SystemStackTraceInformation,
 16     SystemPagedPoolInformation,
 17     SystemNonPagedPoolInformation,
 18     SystemHandleInformation,
 19     SystemObjectInformation,
 20     SystemPageFileInformation,
 21     SystemVdmInstemulInformation,
 22     SystemVdmBopInformation,
 23     SystemFileCacheInformation,
 24     SystemPoolTagInformation,
 25     SystemInterruptInformation,
 26     SystemDpcBehaviorInformation,
 27     SystemFullMemoryInformation,
 28     SystemLoadGdiDriverInformation,
 29     SystemUnloadGdiDriverInformation,
 30     SystemTimeAdjustmentInformation,
 31     SystemSummaryMemoryInformation,
 32     SystemMirrorMemoryInformation,
 33     SystemPerformanceTraceInformation,
 34     SystemObsolete0,
 35     SystemExceptionInformation,
 36     SystemCrashDumpStateInformation,
 37     SystemKernelDebuggerInformation,
 38     SystemContextSwitchInformation,
 39     SystemRegistryQuotaInformation,
 40     SystemExtendServiceTableInformation,
 41     SystemPrioritySeperation,
 42     SystemVerifierAddDriverInformation,
 43     SystemVerifierRemoveDriverInformation,
 44     SystemProcessorIdleInformation,
 45     SystemLegacyDriverInformation,
 46     SystemCurrentTimeZoneInformation,
 47     SystemLookasideInformation,
 48     SystemTimeSlipNotification,
 49     SystemSessionCreate,
 50     SystemSessionDetach,
 51     SystemSessionInformation,
 52     SystemRangeStartInformation,
 53     SystemVerifierInformation,
 54     SystemVerifierThunkExtend,
 55     SystemSessionProcessInformation,
 56     SystemLoadGdiDriverInSystemSpace,
 57     SystemNumaProcessorMap,
 58     SystemPrefetcherInformation,
 59     SystemExtendedProcessInformation,
 60     SystemRecommendedSharedDataAlignment,
 61     SystemComPlusPackage,
 62     SystemNumaAvailableMemory,
 63     SystemProcessorPowerInformation,
 64     SystemEmulationBasicInformation,
 65     SystemEmulationProcessorInformation,
 66     SystemExtendedHandleInformation,
 67     SystemLostDelayedWriteInformation,
 68     SystemBigPoolInformation,
 69     SystemSessionPoolTagInformation,
 70     SystemSessionMappedViewInformation,
 71     SystemHotpatchInformation,
 72     SystemObjectSecurityMode,
 73     SystemWatchdogTimerHandler,
 74     SystemWatchdogTimerInformation,
 75     SystemLogicalProcessorInformation,
 76     SystemWow64SharedInformation,
 77     SystemRegisterFirmwareTableInformationHandler,
 78     SystemFirmwareTableInformation,
 79     SystemModuleInformationEx,
 80     SystemVerifierTriageInformation,
 81     SystemSuperfetchInformation,
 82     SystemMemoryListInformation,
 83     SystemFileCacheInformationEx,
 84     MaxSystemInfoClass,  // MaxSystemInfoClass should always be the last enum
 85
 86     SystemPageMemoryInformation = 123
 87 } SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;
 88
 89 typedef struct _SYSTEM_BASIC_INFORMATION
 90 {
 91     ULONG Unknown; //Always contains zero
 92     ULONG MaximumIncrement; //一个时钟的计量单位
 93     ULONG PhysicalPageSize; //一个内存页的大小
 94     ULONG NumberOfPhysicalPages; //系统管理着多少个页
 95     ULONG LowestPhysicalPage; //低端内存页
 96     ULONG HighestPhysicalPage; //高端内存页
 97     ULONG AllocationGranularity;
 98     ULONG LowestUserAddress; //地端用户地址
 99     ULONG HighestUserAddress; //高端用户地址
100     ULONG ActiveProcessors; //激活的处理器
101     UCHAR NumberProcessors; //有多少个处理器
102 }SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
103
104 NTSTATUS (__stdcall *ZwQuerySystemInformation)(
105     _In_      SYSTEM_INFORMATION_CLASS SystemInformationClass,
106     _Inout_   PVOID                    SystemInformation,
107     _In_      ULONG                    SystemInformationLength,
108     _Out_opt_ PULONG                   ReturnLength) = 0;
109
110
111 int _tmain(int argc, _TCHAR* argv[])
112 {
113     //方式一 ZwQuerySystemInformation
114     HMODULE hNtdll = GetModuleHandle(_T("ntdll.dll"));
115     *(LPVOID *)&ZwQuerySystemInformation = GetProcAddress(hNtdll, "ZwQuerySystemInformation");
116
117     SYSTEM_BASIC_INFORMATION sbi = { 0 };
118     ZwQuerySystemInformation(
119         SystemBasicInformation,
120         &sbi,
121         sizeof(sbi),
122         NULL);
123
124     unsigned __int64 nsize = (unsigned __int64)sbi.NumberOfPhysicalPages * sbi.PhysicalPageSize;
125
126
127     //方式二 GlobalMemoryStatusEx
128     MEMORYSTATUSEX msex;
129     msex.dwLength = sizeof(msex);
130     GlobalMemoryStatusEx(&msex);
131     msex.ullTotalPhys;//物理内存大小
132
133     return 0;
134 }
时间: 2024-08-01 13:54:10

Windows获取物理内存的2种方式 - 随笔记录的相关文章

【Struts2】Struts2获取session的三种方式

1.Map<String,Object> map =  ActionContext.getContext().getSession(); 2.HttpSession session = ServletActionContext.getRequest().getSession(); 3.让Action实现SessionAware接口,并实现public void setSession(Map<String, Object> session) {} 方法,Struts2会在实例化Act

AngularJS中获取数据源的几种方式

在AngularJS中,可以从$rootScope中获取数据源,也可以把获取数据的逻辑封装在service中,然后注入到app.run函数中,或者注入到controller中.本篇就来整理获取数据的几种方式. ■ 数据源放在$rootScope中 var app = angular.module("app",[]); app.run(function($rootScope){ $rootScope.todos = [ {item:"",done:true}, {it

windows 内存管理的几种方式及其优缺点

windows 内存管理方式主要分为:页式管理,段式管理,段页式管理. 页式管理的基本原理是将各进程的虚拟空间划分为若干个长度相等的页:页式管理把内存空间按照页的大小划分成片或者页面,然后把页式虚拟地址与内存地址建立一一对应的页表:并用相应的硬件地址变换机构来解决离散地址变换问题.页式管理采用请求调页或预调页技术来实现内外存存储器的统一管理.其优点是没有外碎片,每个内碎片不超过页的大小.缺点是,程序全部装入内存,要求有相应的硬件支持.例如地址变换机构缺页中断的产生和选择淘汰页面等都要求有相应的硬

java中获取路径的几种方式

总是忘记, 备份一下,方便下次用. 第一种: File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath() ;System.out.println(courseFile); 结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前类的所在工程路径; 第二种: File f = new File(th

java动态获取WebService的两种方式(复杂参数类型)

java动态获取WebService的两种方式(复杂参数类型) 第一种: @Override public OrderSearchListRes searchOrderList(Order_FlightOrderSearchRequest request) { Object myAllMessage; OrderSearchListRes response = null; try { String endpoint = carGlobalSetting.getEndpoint(); JaxWsD

点击li获取下标的几种方式(原生JS实现)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)

方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObjectSupport 方法四:继承自抽象类WebApplicationObjectSupport 方法五:实现接口ApplicationContextAware 方法六:通过Spring提供的ContextLoader 获取spring中bean的方式总结: 方法一:在初始化时保存Applicati

struts2的action从request获取参数值的几种方式

使用jquery框架的ajax能够方便的向后台传递参数,以$.post为例,参数有2种方式字符串和键值对: $.post(url, "name=aty&age=25")和$.post(url, {"name":"aty","age":25}).显然,使用json的方式比使用字符串拼接要方 便.对于后台的action来说,这2种方式是等价的,而且jquery也提供了param.serialize.serialize能够实

Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式

转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236  Spring获取ApplicationContext方式 我自己常用的方法: 读取一个文件1 //创建Spring容器 2 ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); 3 //获取chinese 实例 4 Person p = ctx.g