From 90162c0ee967afa20c45af8ed0e53c0486d79a23 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 31 Aug 2023 15:04:24 -0700 Subject: [PATCH] Reuse sub-allocation instead of re-creating. --- src/gpgmm/common/MemoryAllocator.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gpgmm/common/MemoryAllocator.h b/src/gpgmm/common/MemoryAllocator.h index bf8559b8..81836e3f 100644 --- a/src/gpgmm/common/MemoryAllocator.h +++ b/src/gpgmm/common/MemoryAllocator.h @@ -249,14 +249,17 @@ namespace gpgmm { allocatedMemoryResult.AcquireResult(); ASSERT(memoryAllocation->GetMemory() != nullptr); + // Increment the sub-allocation count so the sub-allocator knows when to + // safely deallocate the underlying memory allocation. memoryAllocation->GetMemory()->Ref(); // Caller is be responsible in fully initializing the memory allocation. // This is because TrySubAllocateMemory() does not necessarily know how to map the // final sub-allocated block to created memory. - return std::make_unique( - nullptr, memoryAllocation->GetMemory(), kInvalidOffset, - AllocationMethod::kUndefined, block, requestSize); + memoryAllocation->SetBlock(block); + memoryAllocation->SetMethod(AllocationMethod::kUndefined); + + return memoryAllocation; } void InsertIntoChain(ScopedRef next);