Add BumpPtrAllocator::getTotalMemory() to allow clients to query how much memory...
authorTed Kremenek <kremenek@apple.com>
Mon, 18 Apr 2011 22:44:46 +0000 (22:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 18 Apr 2011 22:44:46 +0000 (22:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129727 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Allocator.h
lib/Support/Allocator.cpp

index c6807099f85e5ecbfc0a8058afb58a502480e7d3..a2ad24ffead93bd995f50101e9c37063e30e9960 100644 (file)
@@ -177,6 +177,9 @@ public:
   unsigned GetNumSlabs() const;
 
   void PrintStats() const;
+  
+  /// Compute the total physical memory allocated by this allocator.
+  size_t getTotalMemory() const;
 };
 
 /// SpecificBumpPtrAllocator - Same as BumpPtrAllocator but allows only
index 5e27df6628ebbb2524d70eb4f02b3d366fede742..215b0f249d96f82cda56763998be5326fae3569e 100644 (file)
@@ -136,6 +136,14 @@ unsigned BumpPtrAllocator::GetNumSlabs() const {
   return NumSlabs;
 }
 
+size_t BumpPtrAllocator::getTotalMemory() const {
+  size_t TotalMemory = 0;
+  for (MemSlab *Slab = CurSlab; Slab != 0; Slab = Slab->NextPtr) {
+    TotalMemory += Slab->Size;
+  }
+  return TotalMemory;
+}
+  
 void BumpPtrAllocator::PrintStats() const {
   unsigned NumSlabs = 0;
   size_t TotalMemory = 0;