diff options
| author | degasus <wickmarkus@web.de> | 2015-05-16 15:26:11 +0200 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2015-05-16 15:39:36 +0200 |
| commit | 562b9d4a9f3710a65a2987a3c1a88e00778c6d67 (patch) | |
| tree | b61324338ea5f20646d3ba2d4d01e931e6fff955 /Source/Core/Common/MemoryUtil.cpp | |
| parent | 242f7d964d30c37f8547a0763484f68d2bdcaef1 (diff) | |
VideoCommon: Abort texture prefetching on low RAM
There is no nice way to correctly "detect" the "used" memory, so we just say
we're fine to use 50% of the physical memory for custom textures.
This will fix out-of-memory crashes, but we still might run into swapping issues.
Diffstat (limited to 'Source/Core/Common/MemoryUtil.cpp')
| -rw-r--r-- | Source/Core/Common/MemoryUtil.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp index db60a475ed..36de6b23a0 100644 --- a/Source/Core/Common/MemoryUtil.cpp +++ b/Source/Core/Common/MemoryUtil.cpp @@ -19,6 +19,12 @@ #else #include <stdio.h> #include <sys/mman.h> +#include <sys/types.h> +#ifdef __APPLE__ +#include <sys/sysctl.h> +#else +#include <sys/sysinfo.h> +#endif #endif // Valgrind doesn't support MAP_32BIT. @@ -241,3 +247,26 @@ std::string MemUsage() return ""; #endif } + + +size_t MemPhysical() +{ +#ifdef _WIN32 + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullTotalPhys; +#elif defined(__APPLE__) + int mib[2]; + size_t physical_memory; + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; + size_t length = sizeof(size_t); + sysctl(mib, 2, &physical_memory, &length, NULL, 0); + return physical_memory; +#else + struct sysinfo memInfo; + sysinfo (&memInfo); + return (size_t)memInfo.totalram * memInfo.mem_unit; +#endif +} |
