Which standard C++ features can be used for querying machine/OS architecture?

后端 未结 4 1802
难免孤独
难免孤独 2021-02-05 12:07

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,

4条回答
  •  野性不改
    2021-02-05 12:28

    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.

    I've successfully used SIGAR in the past:

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

    • 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

    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".

提交回复
热议问题