Added Reset() to free all allocated memory regions and reset state to be the same...
authorEvan Cheng <evan.cheng@apple.com>
Wed, 5 Sep 2007 21:41:34 +0000 (21:41 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 5 Sep 2007 21:41:34 +0000 (21:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41728 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 527d4c6e2cbf30f2cb55fc2f122726bec636c8d9..f23a41f17fa5de1b8b5d6abb7d884f3acd8fa4bf 100644 (file)
@@ -23,6 +23,7 @@ public:
   MallocAllocator() {}
   ~MallocAllocator() {}
   
+  void Reset() {}
   void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); }
   void Deallocate(void *Ptr) { free(Ptr); }
   void PrintStats() const {}
@@ -38,6 +39,7 @@ public:
   BumpPtrAllocator();
   ~BumpPtrAllocator();
   
+  void Reset();
   void *Allocate(unsigned Size, unsigned Alignment);
   void Deallocate(void *Ptr) {}
   void PrintStats() const;
index 234fd41b73832199fc1d6b4c0aa510570ce073b9..e68c3e26c7db159bc3b34661ed9eef7b5643721d 100644 (file)
@@ -92,6 +92,12 @@ BumpPtrAllocator::~BumpPtrAllocator() {
   ((MemRegion*)TheMemory)->Deallocate();
 }
 
+void BumpPtrAllocator::Reset() {
+  ((MemRegion*)TheMemory)->Deallocate();
+  TheMemory = malloc(4096);
+  ((MemRegion*)TheMemory)->Init(4096, 1, 0);
+}
+
 void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) {
   MemRegion *MRP = (MemRegion*)TheMemory;
   void *Ptr = MRP->Allocate(Size, Align, &MRP);