Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
204:29b70bdaacdc | 205:05154c7bb90b |
---|---|
20 | 20 |
21 #include "system/System.h" | 21 #include "system/System.h" |
22 | 22 |
23 #include <iostream> | 23 #include <iostream> |
24 | 24 |
25 long StorageAdviser::m_discPlanned = 0; | |
26 long StorageAdviser::m_memoryPlanned = 0; | |
27 | |
25 StorageAdviser::Recommendation | 28 StorageAdviser::Recommendation |
26 StorageAdviser::recommend(Criteria criteria, | 29 StorageAdviser::recommend(Criteria criteria, |
27 int minimumSize, | 30 int minimumSize, |
28 int maximumSize) | 31 int maximumSize) |
29 { | 32 { |
33 | 36 |
34 QString path = TempDirectory::getInstance()->getPath(); | 37 QString path = TempDirectory::getInstance()->getPath(); |
35 int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit()); | 38 int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit()); |
36 int memoryFree, memoryTotal; | 39 int memoryFree, memoryTotal; |
37 GetRealMemoryMBAvailable(memoryFree, memoryTotal); | 40 GetRealMemoryMBAvailable(memoryFree, memoryTotal); |
41 | |
42 if (discFree > m_discPlanned / 1024 + 1) { | |
43 discFree -= m_discPlanned / 1024 + 1; | |
44 } else if (discFree > 0) { // can also be -1 for unknown | |
45 discFree = 0; | |
46 } | |
47 | |
48 if (memoryFree > m_memoryPlanned / 1024 + 1) { | |
49 memoryFree -= m_memoryPlanned / 1024 + 1; | |
50 } else if (memoryFree > 0) { // can also be -1 for unknown | |
51 memoryFree = 0; | |
52 } | |
38 | 53 |
39 std::cerr << "Disc space: " << discFree << ", memory free: " << memoryFree << ", memory total: " << memoryTotal << std::endl; | 54 std::cerr << "Disc space: " << discFree << ", memory free: " << memoryFree << ", memory total: " << memoryTotal << std::endl; |
40 | 55 |
41 //!!! We have a potentially serious problem here if multiple | 56 //!!! We have a potentially serious problem here if multiple |
42 //recommendations are made in advance of any of the resulting | 57 //recommendations are made in advance of any of the resulting |
145 } | 160 } |
146 | 161 |
147 return Recommendation(recommendation); | 162 return Recommendation(recommendation); |
148 } | 163 } |
149 | 164 |
165 void | |
166 StorageAdviser::notifyPlannedAllocation(AllocationArea area, int size) | |
167 { | |
168 if (area == MemoryAllocation) m_memoryPlanned += size; | |
169 else if (area == DiscAllocation) m_discPlanned += size; | |
170 std::cerr << "storage planned up: memory: " << m_memoryPlanned << ", disc " | |
171 << m_discPlanned << std::endl; | |
172 } | |
173 | |
174 void | |
175 StorageAdviser::notifyDoneAllocation(AllocationArea area, int size) | |
176 { | |
177 if (area == MemoryAllocation) { | |
178 if (m_memoryPlanned > size) m_memoryPlanned -= size; | |
179 else m_memoryPlanned = 0; | |
180 } else if (area == DiscAllocation) { | |
181 if (m_discPlanned > size) m_discPlanned -= size; | |
182 else m_discPlanned = 0; | |
183 } | |
184 std::cerr << "storage planned down: memory: " << m_memoryPlanned << ", disc " | |
185 << m_discPlanned << std::endl; | |
186 } | |
187 |