惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
WordPress大学
WordPress大学
罗磊的独立博客
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
S
SegmentFault 最新的问题
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
D
DataBreaches.Net
雷峰网
雷峰网
GbyAI
GbyAI
宝玉的分享
宝玉的分享

又见苍岚

COLMAP PatchMatch Stereo 算法详解 事件驱动的状态机框架:从理论到工程实践 Git 在国内网络环境下无法 Push 的排查与修复 —— 配置 Clash 代理 分段五次多项式插值原理详解 路径插值方法深度对比研究 Claude Code 使用指南 OpenClaw 记忆管理与技能创建指南 CBS(Conflict-Based Search)算法详解 A* 算法及其变种详解 OpenClaw 配置多 Agents Windows Powershell 无法加载文件,因为在此系统上禁止运行脚本问题的解决方案 MaxClaw 安装流程 大模型 AI 名词介绍 AList 网盘聚合工具简介 Protobuf 简介与测试 Claude Code 简介以及 GLM 4.7 模型接入 Github 歌词下载工具 163MusicLyrics Python __getattr__ 懒加载 Python TypedDict 机器人仿真平台 Gazebo 安装记录 机器人仿真平台 Gazebo 简介 多机器人路径规划问题(Multi-Agent Path Finding, MAPF)简介 Python exifread 读取修改过的 jpeg 信息错误问题修复 3D 坐标系变换的理解 3D 旋转矩阵基本概念 MongoDB Compass 介绍 Python 环境管理工具 uv Flutter 开发指南 Snipaste 安装下载与黑屏问题解决方案 全局路径规划算法记录
C++ 获取系统信息
Yiwei Zhang · 2023-03-16 · via 又见苍岚

本文最后更新于:2024年5月11日 下午

C++ 工程中可能会用到系统信息,本文记录获取方法。

获取方法

使用 GetSystemInfo 函数获得系统信息

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include

#include

int main(int argc, PCHAR argv[]){

SYSTEM_INFO si;

GetSystemInfo(&si);

if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64){

printf("处理器架构: X64(AMD or Intel)\n");

} else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM){

printf("处理器架构: AMD\n");

} else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64){

printf("处理器架构: Intel 服务器\n");

} else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL){

printf("处理器架构: X86\n");

} else{

printf("处理器架构: 未知的架构\n");

}

printf("程序或DLL最低可用内存地址: 0x%X\n", si.lpMinimumApplicationAddress);

printf("程序或DLL最高可用内存地址: 0x%X\n", si.lpMaximumApplicationAddress);

printf("配置到系统的处理器: %d 15 = 0000 0000 0000 0000 0000 0000 0000 1111\n", si.dwActiveProcessorMask);

/// 常用于获得当前可处理数据的子线程
printf("当前组中的逻辑处理器个数: %d 个\n", si.dwNumberOfProcessors);

printf("页面分配粒度: 0x%x 字节\n", si.dwPageSize);

printf("虚拟内存分配粒度: 0x%x 字节\n", si.dwAllocationGranularity);

if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL){

printf("依赖架构的处理器级别: %d [仅用于显示][由CPU供应商定义]\n", si.wProcessorLevel);

}

if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64){

printf("依赖架构的处理器级别: %d [仅用于显示][设置为1]\n", si.wProcessorLevel);

}

printf("处理器的型号: %X\n", si.wProcessorRevision);

getchar();

return 0;
}

本机输出:

1
2
3
4
5
6
7
8
处理器架构: X64(AMD or Intel)
程序或DLL最低可用内存地址: 0x10000
程序或DLL最高可用内存地址: 0xFFFEFFFF
配置到系统的处理器: 4095 15 = 0000 0000 0000 0000 0000 0000 0000 1111
当前组中的逻辑处理器个数: 12
页面分配粒度: 0x1000 字节
虚拟内存分配粒度: 0x10000 字节
处理器的型号: 9E0A

参考资料

文章链接:
https://www.zywvvd.com/notes/coding/cpp/cpp-getsystem-info/getsystem-info/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付