Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
sysinfo.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
18
19// Mac OSX implementation:
20#if defined(__MACH__)
21 #include <sys/sysctl.h>
22 #include <sys/types.h>
23
24std::optional<std::size_t> sham::getPhysicalMemory() {
25
26 int mib[] = {CTL_HW, HW_MEMSIZE};
27 int64_t value = 0;
28 size_t length = sizeof(value);
29
30 if (-1 == sysctl(mib, 2, &value, &length, NULL, 0)) {
31 return std::nullopt;
32 }
33 return value;
34}
35
36// Linux/BSD implementation:
37#elif (defined(linux) || defined(__linux__) || defined(__linux)) \
38 || (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) \
39 || defined(__OpenBSD__))
40
41 #include <sys/sysinfo.h>
42
43std::optional<std::size_t> sham::getPhysicalMemory() {
44 struct sysinfo info;
45 sysinfo(&info);
46 return info.totalram;
47}
48
49#else
50
51std::optional<std::size_t> sham::getPhysicalMemory() { return std::nullopt; }
52
53#endif
std::optional< std::size_t > getPhysicalMemory()
Get the amount of physical memory (RAM) available on the system, in bytes.
Definition sysinfo.cpp:51
void info(std::string module_name, Types... var2)
Prints a log message with multiple arguments.
Definition logs.hpp:133