8 #include "RegionalCachingAlgorithm.h"
17 #include "RawCubeChunk.h"
18 #include "Statistics.h"
23 CubeCachingAlgorithm::CacheResult
26 const Buffer &justRequested) {
28 if(allocated.size() && allocated[0] != NULL) {
34 int largestChunkDim = max( max( allocated[0]->sampleCount(),
35 allocated[0]->lineCount()),
36 allocated[0]->bandCount());
42 int numToKeep = (int)ceil(avgLargestDim / largestChunkDim) * 1;
45 int approxBytesPerChunk = allocated[0]->getByteCount();
47 int tenMB = 10 * 1024 * 1024;
48 if(numToKeep * approxBytesPerChunk > tenMB) {
49 numToKeep = tenMB / approxBytesPerChunk;
52 if(numToKeep < justUsed.size())
53 numToKeep = justUsed.size();
55 int numToToss = allocated.size() - numToKeep;
59 QListIterator<RawCubeChunk *> allocatedIterator(allocated);
61 while(numToToss > 0 && allocatedIterator.hasNext()) {
64 if(justUsed.indexOf(chunk) == -1) {
66 chunksToToss.append(chunk);