MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / getSystemTotalRAM

Function getSystemTotalRAM

Engine/MemoryInfo.cpp:80–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78#include "Global/GlobalDefines.h"
79
80NATRON_NAMESPACE_ENTER
81
82U64
83getSystemTotalRAM()
84{
85#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
86 // see http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/kernel32/heap.c
87 uint64_t total;
88#ifdef __APPLE__
89 unsigned int val;
90#else
91 unsigned long val;
92#endif
93 int mib[2];
94 size_t size_sys;
95#ifdef HW_MEMSIZE
96 uint64_t val64 = 0;
97#endif
98 total = 0;
99
100 mib[0] = CTL_HW;
101#ifdef HW_MEMSIZE
102 mib[1] = HW_MEMSIZE;
103 size_sys = sizeof(val64);
104 if (!sysctl(mib, 2, &val64, &size_sys, NULL, 0) && size_sys == sizeof(val64) && val64) {
105 total = val64;
106 }
107#endif
108
109#if defined(__MACH__)
110 if (!total) {
111 host_name_port_t host = mach_host_self();
112 mach_msg_type_number_t count;
113
114 host_basic_info_data_t info;
115 count = HOST_BASIC_INFO_COUNT;
116 if (host_info(host, HOST_BASIC_INFO, (host_info_t)&info, &count) == KERN_SUCCESS) {
117 total = info.max_mem;
118 }
119
120 mach_port_deallocate(mach_task_self(), host);
121 }
122#endif
123
124 if (!total) {
125 mib[1] = HW_PHYSMEM;
126 size_sys = sizeof(val);
127 if (!sysctl(mib, 2, &val, &size_sys, NULL, 0) && size_sys == sizeof(val) && val) {
128 total = val;
129 }
130 }
131
132 return total;
133
134#elif defined(_WIN32)
135 ///On Windows, but not Cygwin, the new GlobalMemoryStatusEx( ) function fills a 64-bit
136 ///safe MEMORYSTATUSEX struct with information about physical and virtual memory. Structure fields include:
137 MEMORYSTATUSEX status;

Callers 7

setCachingLabelsMethod · 0.85
onKnobValueChangedMethod · 0.85
CacheMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected