comparison system/System.cpp @ 1779:85903b0e9b42

Update macOS memory size check - the original sysctl was returning far too small a value for modern machines (because bounded to a 32-bit int)
author Chris Cannam
date Wed, 11 Sep 2019 13:20:40 +0100
parents 70e172e6cc59
children c5ee0746bdef
comparison
equal deleted inserted replaced
1778:59d9dcfd67c2 1779:85903b0e9b42
184 return; 184 return;
185 185
186 #else 186 #else
187 #ifdef __APPLE__ 187 #ifdef __APPLE__
188 188
189 unsigned int val; 189 unsigned int val32;
190 int64_t val64;
190 int mib[2]; 191 int mib[2];
191 size_t size_sys; 192 size_t size_sys;
192 193
193 mib[0] = CTL_HW; 194 mib[0] = CTL_HW;
194 195
195 mib[1] = HW_PHYSMEM; 196 mib[1] = HW_MEMSIZE;
196 size_sys = sizeof(val); 197 size_sys = sizeof(val64);
197 sysctl(mib, 2, &val, &size_sys, NULL, 0); 198 sysctl(mib, 2, &val64, &size_sys, NULL, 0);
198 if (val) total = val / 1048576; 199 if (val64) total = val64 / 1048576;
199 200
200 mib[1] = HW_USERMEM; 201 mib[1] = HW_USERMEM;
201 size_sys = sizeof(val); 202 size_sys = sizeof(val32);
202 sysctl(mib, 2, &val, &size_sys, NULL, 0); 203 sysctl(mib, 2, &val32, &size_sys, NULL, 0);
203 if (val) available = val / 1048576; 204 if (val32) available = val32 / 1048576;
205
206 // The newer memsize sysctl returns a 64-bit value, but usermem is
207 // an old 32-bit value that doesn't seem to have an updated
208 // alternative (?) - so it can't return more than 2G. In practice
209 // it seems to return values far lower than that, even where more
210 // than 2G of real memory is free. So we can't actually tell when
211 // we're getting low on memory at all. Most of the time I think we
212 // just need to use an arbitrary value like this one.
213 if (available < total/4) {
214 available = total/4;
215 }
204 216
205 return; 217 return;
206 218
207 #else 219 #else
208 220