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

Function getSystemTotalRAM

Engine/MemoryInfo.cpp:79–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 6

setCachingLabelsMethod · 0.85
CacheMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected