summaryrefslogtreecommitdiffstats
path: root/src/common/memory_detect.cpp
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2020-05-17 20:45:12 +0200
committerMorph <39850852+Morph1984@users.noreply.github.com>2020-05-17 20:45:12 +0200
commit9a36d8600c0b263b4b3861b64051a4f62b4251d2 (patch)
tree65714fc37ebf294332c533db8b2dcefb67ef2562 /src/common/memory_detect.cpp
parentMerge pull request #3665 from bunnei/device-save (diff)
downloadyuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.gz
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.bz2
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.lz
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.xz
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.zst
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.zip
Diffstat (limited to 'src/common/memory_detect.cpp')
-rw-r--r--src/common/memory_detect.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/common/memory_detect.cpp b/src/common/memory_detect.cpp
new file mode 100644
index 000000000..b59a45d55
--- /dev/null
+++ b/src/common/memory_detect.cpp
@@ -0,0 +1,57 @@
+// 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;
+ // hw and vm are defined in sysctl.h
+ // https://github.com/apple/darwin-xnu/blob/master/bsd/sys/sysctl.h#L471
+ 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