diff system/System.cpp @ 1401:cc62d7862203

Some bits and bobs to do with handling memory pressure
author Chris Cannam
date Mon, 06 Mar 2017 17:23:46 +0000
parents 39271c98cbdd
children 91231350ee22
line wrap: on
line diff
--- a/system/System.cpp	Mon Mar 06 09:35:03 2017 +0000
+++ b/system/System.cpp	Mon Mar 06 17:23:46 2017 +0000
@@ -181,6 +181,24 @@
     if (size > INT_MAX) size = INT_MAX;
     total = ssize_t(size);
 
+    // In 32-bit addressing mode we can't address more than 4Gb.
+    // If the total memory is reported as more than 4Gb, we should
+    // reduce the available amount by the difference between 4Gb
+    // and the total. This won't give us an accurate idea of the
+    // amount of memory available any more, but it should be enough
+    // to prevent us from trying to allocate more for our own use
+    // than can be addressed at all!
+    if (sizeof(void *) < 8) {
+        if (total > 4096) {
+            ssize_t excess = total - 4096;
+            if (available > excess) {
+                available -= excess;
+            } else {
+                available = 0;
+            }
+        }
+    }
+
     return;
 
 #else