* Keep some statistics about memory allocation.
This commit is contained in:
parent
b803fb95cb
commit
6980544467
1 changed files with 16 additions and 5 deletions
|
@ -65,6 +65,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static const unsigned int maxLoadFactor = /* 1 / */ 3;
|
||||||
|
static unsigned int nrResizes = 0;
|
||||||
|
static unsigned int sizeTotalAlloc = 0;
|
||||||
|
static unsigned int sizeCurAlloc = 0;
|
||||||
|
static unsigned int sizeMaxAlloc = 0;
|
||||||
|
|
||||||
|
|
||||||
ATermMap::ATermMap(unsigned int expectedCount)
|
ATermMap::ATermMap(unsigned int expectedCount)
|
||||||
{
|
{
|
||||||
init(expectedCount * 10 / 9); /* slight adjustment */
|
init(expectedCount * 10 / 9); /* slight adjustment */
|
||||||
|
@ -110,6 +117,7 @@ void ATermMap::free()
|
||||||
if (hashTable) {
|
if (hashTable) {
|
||||||
ATunprotectArray((ATerm *) hashTable);
|
ATunprotectArray((ATerm *) hashTable);
|
||||||
::free(hashTable);
|
::free(hashTable);
|
||||||
|
sizeCurAlloc -= sizeof(KeyValue) * capacity;
|
||||||
hashTable = 0;
|
hashTable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,10 +132,6 @@ static unsigned int roundToPowerOf2(unsigned int x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const unsigned int maxLoadFactor = /* 1 / */ 3;
|
|
||||||
static unsigned int nrResizes = 0;
|
|
||||||
|
|
||||||
|
|
||||||
void ATermMap::resizeTable(unsigned int expectedCount)
|
void ATermMap::resizeTable(unsigned int expectedCount)
|
||||||
{
|
{
|
||||||
if (expectedCount == 0) expectedCount = 1;
|
if (expectedCount == 0) expectedCount = 1;
|
||||||
|
@ -141,6 +145,9 @@ void ATermMap::resizeTable(unsigned int expectedCount)
|
||||||
maxCount = expectedCount;
|
maxCount = expectedCount;
|
||||||
capacity = roundToPowerOf2(maxCount * maxLoadFactor);
|
capacity = roundToPowerOf2(maxCount * maxLoadFactor);
|
||||||
hashTable = (KeyValue *) calloc(sizeof(KeyValue), capacity);
|
hashTable = (KeyValue *) calloc(sizeof(KeyValue), capacity);
|
||||||
|
sizeTotalAlloc += sizeof(KeyValue) * capacity;
|
||||||
|
sizeCurAlloc += sizeof(KeyValue) * capacity;
|
||||||
|
if (sizeCurAlloc > sizeMaxAlloc) sizeMaxAlloc = sizeCurAlloc;
|
||||||
ATprotectArray((ATerm *) hashTable, capacity * 2);
|
ATprotectArray((ATerm *) hashTable, capacity * 2);
|
||||||
|
|
||||||
// cout << capacity << endl;
|
// cout << capacity << endl;
|
||||||
|
@ -151,6 +158,7 @@ void ATermMap::resizeTable(unsigned int expectedCount)
|
||||||
copy(oldHashTable, oldCapacity);
|
copy(oldHashTable, oldCapacity);
|
||||||
ATunprotectArray((ATerm *) oldHashTable);
|
ATunprotectArray((ATerm *) oldHashTable);
|
||||||
::free(oldHashTable);
|
::free(oldHashTable);
|
||||||
|
sizeCurAlloc -= sizeof(KeyValue) * oldCapacity;
|
||||||
nrResizes++;
|
nrResizes++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +333,10 @@ int main(int argc, char * * argv)
|
||||||
map.get(someTerm());
|
map.get(someTerm());
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "RESIZES: " << nrResizes << endl;
|
cout << "RESIZES: " << nrResizes << " "
|
||||||
|
<< sizeTotalAlloc << " "
|
||||||
|
<< sizeCurAlloc << " "
|
||||||
|
<< sizeMaxAlloc << endl;
|
||||||
|
|
||||||
cout << "SET: "
|
cout << "SET: "
|
||||||
<< nrItemsSet << " "
|
<< nrItemsSet << " "
|
||||||
|
|
Loading…
Reference in a new issue