diff options
author | bunnei <bunneidev@gmail.com> | 2020-05-28 04:58:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-28 04:58:51 +0200 |
commit | 640f0d1cec7cea180b44eac82624e7f382f5da4b (patch) | |
tree | c2b4a3ca8c3799e0701407f432cafe95c8e37512 /src/common/memory_detect.cpp | |
parent | Merge pull request #3961 from Morph1984/bgra8_srgb (diff) | |
parent | Fix macOS code and change "Swapfile" to "Swap" (diff) | |
download | yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar.gz yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar.bz2 yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar.lz yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar.xz yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.tar.zst yuzu-640f0d1cec7cea180b44eac82624e7f382f5da4b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/memory_detect.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/common/memory_detect.cpp b/src/common/memory_detect.cpp new file mode 100644 index 000000000..3fdc309a2 --- /dev/null +++ b/src/common/memory_detect.cpp @@ -0,0 +1,60 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#ifdef _WIN32 +// clang-format off +#include <windows.h> +#include <sysinfoapi.h> +// clang-format on +#else +#include <sys/types.h> +#ifdef __APPLE__ +#include <sys/sysctl.h> +#else +#include <sys/sysinfo.h> +#endif +#endif + +#include "common/memory_detect.h" + +namespace Common { + +// Detects the RAM and Swapfile sizes +static MemoryInfo Detect() { + MemoryInfo mem_info{}; + +#ifdef _WIN32 + MEMORYSTATUSEX memorystatus; + memorystatus.dwLength = sizeof(memorystatus); + GlobalMemoryStatusEx(&memorystatus); + mem_info.TotalPhysicalMemory = memorystatus.ullTotalPhys; + mem_info.TotalSwapMemory = memorystatus.ullTotalPageFile - mem_info.TotalPhysicalMemory; +#elif defined(__APPLE__) + u64 ramsize; + struct xsw_usage vmusage; + std::size_t sizeof_ramsize = sizeof(ramsize); + std::size_t sizeof_vmusage = sizeof(vmusage); + // hw and vm are defined in sysctl.h + // https://github.com/apple/darwin-xnu/blob/master/bsd/sys/sysctl.h#L471 + // sysctlbyname(const char *, void *, size_t *, void *, size_t); + sysctlbyname("hw.memsize", &ramsize, &sizeof_ramsize, NULL, 0); + sysctlbyname("vm.swapusage", &vmusage, &sizeof_vmusage, NULL, 0); + mem_info.TotalPhysicalMemory = ramsize; + mem_info.TotalSwapMemory = vmusage.xsu_total; +#else + struct sysinfo meminfo; + sysinfo(&meminfo); + mem_info.TotalPhysicalMemory = meminfo.totalram; + mem_info.TotalSwapMemory = meminfo.totalswap; +#endif + + return mem_info; +} + +const MemoryInfo& GetMemInfo() { + static MemoryInfo mem_info = Detect(); + return mem_info; +} + +} // namespace Common
\ No newline at end of file |