[llvm-commits] [llvm] r41728 - in /llvm/trunk: include/llvm/Support/Allocator.h lib/Support/Allocator.cpp

Evan Cheng evan.cheng at apple.com
Wed Sep 5 14:41:34 PDT 2007


Author: evancheng
Date: Wed Sep  5 16:41:34 2007
New Revision: 41728

URL: http://llvm.org/viewvc/llvm-project?rev=41728&view=rev
Log:
Added Reset() to free all allocated memory regions and reset state to be the same as right after ctor.

Modified:
    llvm/trunk/include/llvm/Support/Allocator.h
    llvm/trunk/lib/Support/Allocator.cpp

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=41728&r1=41727&r2=41728&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Wed Sep  5 16:41:34 2007
@@ -23,6 +23,7 @@
   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 @@
   BumpPtrAllocator();
   ~BumpPtrAllocator();
   
+  void Reset();
   void *Allocate(unsigned Size, unsigned Alignment);
   void Deallocate(void *Ptr) {}
   void PrintStats() const;

Modified: llvm/trunk/lib/Support/Allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Allocator.cpp?rev=41728&r1=41727&r2=41728&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Allocator.cpp (original)
+++ llvm/trunk/lib/Support/Allocator.cpp Wed Sep  5 16:41:34 2007
@@ -92,6 +92,12 @@
   ((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);





More information about the llvm-commits mailing list