enum { MaxItemSize = 256 };
Managed *smallItems[MaxItemSize/16];
uint nChunks[MaxItemSize/16];
+ uint availableItems[MaxItemSize/16];
+ uint allocCount[MaxItemSize/16];
struct Chunk {
PageAllocation memory;
int chunkSize;
{
memset(smallItems, 0, sizeof(smallItems));
memset(nChunks, 0, sizeof(nChunks));
+ memset(availableItems, 0, sizeof(availableItems));
+ memset(allocCount, 0, sizeof(allocCount));
scribble = !qgetenv("MM_SCRIBBLE").isEmpty();
aggressiveGC = !qgetenv("MM_AGGRESSIVE_GC").isEmpty();
}
assert(size % 16 == 0);
size_t pos = size >> 4;
+ ++m_d->allocCount[pos];
// fits into a small bucket
assert(size < MemoryManager::Data::MaxItemSize);
goto found;
// try to free up space, otherwise allocate
- if (!m_d->aggressiveGC) {
+ if (m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && !m_d->aggressiveGC) {
runGC();
m = m_d->smallItems[pos];
if (m)
}
*last = 0;
m = m_d->smallItems[pos];
+ m_d->availableItems[pos] += allocation.memory.size()/size - 1;
}
found:
// std::cerr << "GC: sweep freed " << freedCount
// << " objects in " << t.elapsed()
// << "ms" << std::endl;
+ memset(m_d->allocCount, 0, sizeof(m_d->allocCount));
}
void MemoryManager::setEnableGC(bool enableGC)