about summary refs log tree commit diff
path: root/table/aterm-map.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-05-04T08·32+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-05-04T08·32+0000
commit6980544467b42aaefc5b588d8be2f1d7a2badef3 (patch)
tree165e32bf870a02f1a2974a71a8fb693fd294bc55 /table/aterm-map.cc
parentb803fb95cbce33cf37496e1fc947d9721714de44 (diff)
* Keep some statistics about memory allocation.
Diffstat (limited to 'table/aterm-map.cc')
-rw-r--r--table/aterm-map.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/table/aterm-map.cc b/table/aterm-map.cc
index aa7149841db9..df013359263e 100644
--- a/table/aterm-map.cc
+++ b/table/aterm-map.cc
@@ -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)
 {
     init(expectedCount * 10 / 9); /* slight adjustment */
@@ -110,6 +117,7 @@ void ATermMap::free()
     if (hashTable) {
         ATunprotectArray((ATerm *) hashTable);
         ::free(hashTable);
+        sizeCurAlloc -= sizeof(KeyValue) * capacity;
         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)
 {
     if (expectedCount == 0) expectedCount = 1;
@@ -141,6 +145,9 @@ void ATermMap::resizeTable(unsigned int expectedCount)
     maxCount = expectedCount;
     capacity = roundToPowerOf2(maxCount * maxLoadFactor);
     hashTable = (KeyValue *) calloc(sizeof(KeyValue), capacity);
+    sizeTotalAlloc += sizeof(KeyValue) * capacity;
+    sizeCurAlloc += sizeof(KeyValue) * capacity;
+    if (sizeCurAlloc > sizeMaxAlloc) sizeMaxAlloc = sizeCurAlloc;
     ATprotectArray((ATerm *) hashTable, capacity * 2);
     
 //     cout << capacity << endl;
@@ -151,6 +158,7 @@ void ATermMap::resizeTable(unsigned int expectedCount)
         copy(oldHashTable, oldCapacity);
         ATunprotectArray((ATerm *) oldHashTable);
         ::free(oldHashTable);
+        sizeCurAlloc -= sizeof(KeyValue) * oldCapacity;
         nrResizes++;
     }
 }
@@ -325,7 +333,10 @@ int main(int argc, char * * argv)
             map.get(someTerm());
     }
 
-    cout << "RESIZES: " << nrResizes << endl;
+    cout << "RESIZES: " << nrResizes << " "
+         << sizeTotalAlloc << " "
+         << sizeCurAlloc << " "
+         << sizeMaxAlloc << endl;
         
     cout << "SET: "
          << nrItemsSet << " "