哪些标准的C ++特性可以用于查询机器/操作系统架构? [英] Which standard C++ features can be used for querying machine/OS architecture?

查看:145
本文介绍了哪些标准的C ++特性可以用于查询机器/操作系统架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么标准C ++功能和实用程序用于查询运行程序的硬件或操作系统功能的属性?

例如, std :: thread :: hardware_concurrency()给出了机器支持的线程数。

但是如何检测计算机有多少RAM或进程使用了​​多少RAM,或者在某个目录中可以写入多少磁盘空间,或者多少L2缓存可用?

What are the standard C++ features and utilities for querying the properties of the hardware or operating system capabilities, on which the program is running?
For instance, std::thread::hardware_concurrency() gives you the number of threads the machine supports.
But how do you detect how much RAM the computer has, or how much RAM the process is using, or how much disk space is available to write to in a certain directory, or how much L2 cache is available?

我希望通过 c ++ c ++ 14 )标准,但TR2或 boost 建议也会很好。

I would prefer answers by means of c++ (c++14) standards, but TR2 or boost proposals would be good as well.

推荐答案

,用于获得系统的这种性质的功能通常是平台特定的。 STL和boost不提供与平台无关的包装,所以你必须依赖其他第三方库。

As others have pointed out, functions for obtaining such properties of the system are typically platform-specific. The STL and boost do not provide platform-independent wrappers, so you'll have to rely on other third party libraries.

我已成功使用过 SIGAR


Sigar API提供了一个用于收集系统
信息的可移植界面,例如:

The Sigar API provides a portable interface for gathering system information such as:


  • 系统内存,交换,cpu,负载平均,正常运行时间,登录

  • 每进程内存,cpu,凭据信息, ,环境,打开文件

  • 文件系统检测和指标

  • 网络接口检测,配置信息和指标

  • TCP和UDP连接表

  • 网络路由表

  • System memory, swap, cpu, load average, uptime, logins
  • Per-process memory, cpu, credential info, state, arguments, environment, open files
  • File system detection and metrics
  • Network interface detection, configuration info and metrics
  • TCP and UDP connection tables
  • Network route table

另一方面,Boost Filesystem确实提供了 boost :: filesystem: :空格以查询在特定目录中可写入多少磁盘空间。

As a side note, Boost Filesystem does actually provide boost::filesystem::space to query "how much disk space is available to write to in a certain directory".

这篇关于哪些标准的C ++特性可以用于查询机器/操作系统架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆