# HG changeset patch # User Chris Cannam # Date 1568204440 -3600 # Node ID 85903b0e9b4246f35e3d6292f727fe08d867d2a8 # Parent 59d9dcfd67c21eb543d8e27410954f87a830c979 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) diff -r 59d9dcfd67c2 -r 85903b0e9b42 system/System.cpp --- a/system/System.cpp Wed Sep 11 11:19:27 2019 +0100 +++ b/system/System.cpp Wed Sep 11 13:20:40 2019 +0100 @@ -186,21 +186,33 @@ #else #ifdef __APPLE__ - unsigned int val; + unsigned int val32; + int64_t val64; int mib[2]; size_t size_sys; mib[0] = CTL_HW; - mib[1] = HW_PHYSMEM; - size_sys = sizeof(val); - sysctl(mib, 2, &val, &size_sys, NULL, 0); - if (val) total = val / 1048576; + mib[1] = HW_MEMSIZE; + size_sys = sizeof(val64); + sysctl(mib, 2, &val64, &size_sys, NULL, 0); + if (val64) total = val64 / 1048576; mib[1] = HW_USERMEM; - size_sys = sizeof(val); - sysctl(mib, 2, &val, &size_sys, NULL, 0); - if (val) available = val / 1048576; + size_sys = sizeof(val32); + sysctl(mib, 2, &val32, &size_sys, NULL, 0); + if (val32) available = val32 / 1048576; + + // The newer memsize sysctl returns a 64-bit value, but usermem is + // an old 32-bit value that doesn't seem to have an updated + // alternative (?) - so it can't return more than 2G. In practice + // it seems to return values far lower than that, even where more + // than 2G of real memory is free. So we can't actually tell when + // we're getting low on memory at all. Most of the time I think we + // just need to use an arbitrary value like this one. + if (available < total/4) { + available = total/4; + } return;