Smarter Reset(). Instead of deallocating all memory regions and reallocate the

first region, just deallocate all but the last region in the list.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng
2007-09-08 00:02:17 +00:00
parent ef61ed3507
commit 7dfda9e674

View File

@@ -68,14 +68,25 @@ public:
return NewRegion->Allocate(AllocSize, Alignment, RegPtr); return NewRegion->Allocate(AllocSize, Alignment, RegPtr);
} }
/// Deallocate - Release all memory for this region to the system. /// Deallocate - Recursively release all memory for this and its next regions
/// /// to the system.
void Deallocate() { void Deallocate() {
MemRegion *next = Next; MemRegion *next = Next;
free(this); free(this);
if (next) if (next)
next->Deallocate(); next->Deallocate();
} }
/// DeallocateAllButLast - Recursively release all memory for this and its
/// next regions to the system stopping at the last region in the list.
/// Returns the pointer to the last region.
MemRegion *DeallocateAllButLast() {
MemRegion *next = Next;
if (!next)
return this;
free(this);
return next->DeallocateAllButLast();
}
}; };
} }
@@ -93,9 +104,10 @@ BumpPtrAllocator::~BumpPtrAllocator() {
} }
void BumpPtrAllocator::Reset() { void BumpPtrAllocator::Reset() {
((MemRegion*)TheMemory)->Deallocate(); MemRegion *MRP = (MemRegion*)TheMemory;
TheMemory = malloc(4096); MRP = MRP->DeallocateAllButLast();
((MemRegion*)TheMemory)->Init(4096, 1, 0); MRP->Init(4096, 1, 0);
TheMemory = MRP;
} }
void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) { void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) {