Windows获取物理内存的2种方式 - 随笔记录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Windows获取物理内存的2种方式 - 随笔记录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4408字,纯文字阅读大概需要7分钟。
内容图文
![Windows获取物理内存的2种方式 - 随笔记录](/upload/InfoBanner/zyjiaocheng/1122/3334ba836db44c6996d9c56f5afdd66a.jpg)
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; 103104 NTSTATUS (__stdcall *ZwQuerySystemInformation)( 105 _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, 106 _Inout_ PVOID SystemInformation, 107 _In_ ULONG SystemInformationLength, 108 _Out_opt_ PULONG ReturnLength) = 0; 109110111int _tmain(int argc, _TCHAR* argv[]) 112{ 113//方式一 ZwQuerySystemInformation114 HMODULE hNtdll = GetModuleHandle(_T("ntdll.dll")); 115 *(LPVOID *)&ZwQuerySystemInformation = GetProcAddress(hNtdll, "ZwQuerySystemInformation"); 116117 SYSTEM_BASIC_INFORMATION sbi = { 0 }; 118 ZwQuerySystemInformation( 119 SystemBasicInformation, 120 &sbi, 121sizeof(sbi), 122 NULL); 123124 unsigned __int64 nsize = (unsigned __int64)sbi.NumberOfPhysicalPages * sbi.PhysicalPageSize; 125126127//方式二 GlobalMemoryStatusEx128 MEMORYSTATUSEX msex; 129 msex.dwLength = sizeof(msex); 130 GlobalMemoryStatusEx(&msex); 131 msex.ullTotalPhys;//物理内存大小132133return0; 134 }
原文:http://www.cnblogs.com/kindly/p/7427011.html
内容总结
以上是互联网集市为您收集整理的Windows获取物理内存的2种方式 - 随笔记录全部内容,希望文章能够帮你解决Windows获取物理内存的2种方式 - 随笔记录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。