diff base/StorageAdviser.cpp @ 205:05154c7bb90b

* Basics of an approximate way of managing memory that we've committed to using but haven't allocated yet
author Chris Cannam
date Fri, 15 Dec 2006 18:05:31 +0000
parents 91fdc752e540
children dc46851837d6
line wrap: on
line diff
--- a/base/StorageAdviser.cpp	Tue Dec 12 10:41:41 2006 +0000
+++ b/base/StorageAdviser.cpp	Fri Dec 15 18:05:31 2006 +0000
@@ -22,6 +22,9 @@
 
 #include <iostream>
 
+long StorageAdviser::m_discPlanned = 0;
+long StorageAdviser::m_memoryPlanned = 0;
+
 StorageAdviser::Recommendation
 StorageAdviser::recommend(Criteria criteria,
 			  int minimumSize,
@@ -36,6 +39,18 @@
     int memoryFree, memoryTotal;
     GetRealMemoryMBAvailable(memoryFree, memoryTotal);
 
+    if (discFree > m_discPlanned / 1024 + 1) {
+        discFree -= m_discPlanned / 1024 + 1;
+    } else if (discFree > 0) { // can also be -1 for unknown
+        discFree = 0;
+    }
+
+    if (memoryFree > m_memoryPlanned / 1024 + 1) {
+        memoryFree -= m_memoryPlanned / 1024 + 1;
+    } else if (memoryFree > 0) { // can also be -1 for unknown
+        memoryFree = 0;
+    }
+
     std::cerr << "Disc space: " << discFree << ", memory free: " << memoryFree << ", memory total: " << memoryTotal << std::endl;
 
     //!!! We have a potentially serious problem here if multiple
@@ -147,3 +162,26 @@
     return Recommendation(recommendation);
 }
 
+void
+StorageAdviser::notifyPlannedAllocation(AllocationArea area, int size)
+{
+    if (area == MemoryAllocation) m_memoryPlanned += size;
+    else if (area == DiscAllocation) m_discPlanned += size;
+    std::cerr << "storage planned up: memory: " << m_memoryPlanned << ", disc "
+              << m_discPlanned << std::endl;
+}
+
+void
+StorageAdviser::notifyDoneAllocation(AllocationArea area, int size)
+{
+    if (area == MemoryAllocation) {
+        if (m_memoryPlanned > size) m_memoryPlanned -= size;
+        else m_memoryPlanned = 0;
+    } else if (area == DiscAllocation) {
+        if (m_discPlanned > size) m_discPlanned -= size; 
+        else m_discPlanned = 0;
+    }
+    std::cerr << "storage planned down: memory: " << m_memoryPlanned << ", disc "
+              << m_discPlanned << std::endl;
+}
+