From c7391919d2e9d34e7f4fc18e8ffc174a9eabfb5e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 4 Oct 2018 21:51:33 -0700 Subject: Reworked context pool management in D3D12 --- Common/interface/STDAllocator.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/STDAllocator.h b/Common/interface/STDAllocator.h index cf2290be..10f6769a 100644 --- a/Common/interface/STDAllocator.h +++ b/Common/interface/STDAllocator.h @@ -158,17 +158,37 @@ template using STDAllocatorRawMem = STDAllocator; template< class T, typename AllocatorType > struct STDDeleter { - STDDeleter(AllocatorType &Allocator) : - m_Allocator(Allocator) + STDDeleter() noexcept {} + + STDDeleter(AllocatorType& Allocator) noexcept : + m_Allocator(&Allocator) {} - - void operator()(T *ptr) + + STDDeleter (const STDDeleter&) = default; + STDDeleter& operator = (const STDDeleter&) = default; + + STDDeleter(STDDeleter&& rhs) noexcept : + m_Allocator(rhs.m_Allocator) + { + rhs.m_Allocator = nullptr; + } + + STDDeleter& operator = (STDDeleter&& rhs) noexcept { + m_Allocator = rhs.m_Allocator; + rhs.m_Allocator = nullptr; + return *this; + } + + void operator()(T *ptr) noexcept + { + VERIFY(m_Allocator != nullptr, "The deleter has been moved away or never initialized, and can't be used"); ptr->~T(); - m_Allocator.Free(ptr); + m_Allocator->Free(ptr); } - AllocatorType &m_Allocator; +private: + AllocatorType* m_Allocator = nullptr; }; template using STDDeleterRawMem = STDDeleter; -- cgit v1.2.3