11 virtual void*
Allocate(
size_t uiSize,
size_t uiAlign, plMemoryUtils::DestructorFunction destructorFunc =
nullptr)
override;
12 virtual void Deallocate(
void* pPtr)
override;
15 virtual Stats GetStats()
const override;
20 AllocationPolicy m_allocator;
23 plThreadID m_ThreadID;
26 template <
typename AllocationPolicy, plAllocatorTrackingMode TrackingMode,
bool HasReallocate>
33 template <
typename AllocationPolicy, plAllocatorTrackingMode TrackingMode>
38 virtual void* Reallocate(
void* pPtr,
size_t uiCurrentSize,
size_t uiNewSize,
size_t uiAlign)
override;
42template <
typename A, plAllocatorTrackingMode TrackingMode>
44 : m_allocator(pParent)
47 if constexpr (TrackingMode >= plAllocatorTrackingMode::Basics)
49 this->m_Id = plMemoryTracker::RegisterAllocator(sName, TrackingMode, pParent !=
nullptr ? pParent->GetId() :
plAllocatorId());
53template <
typename A, plAllocatorTrackingMode TrackingMode>
56 if constexpr (TrackingMode >= plAllocatorTrackingMode::Basics)
58 plMemoryTracker::DeregisterAllocator(this->m_Id);
62template <
typename A, plAllocatorTrackingMode TrackingMode>
69 PL_ASSERT_DEBUG(
plMath::IsPowerOf2((plUInt32)uiAlign),
"Alignment must be power of two");
73 void* ptr = m_allocator.Allocate(uiSize, uiAlign);
74 PL_ASSERT_DEV(ptr !=
nullptr,
"Could not allocate {0} bytes. Out of memory?", uiSize);
76 if constexpr (TrackingMode >= plAllocatorTrackingMode::AllocationStats)
78 plMemoryTracker::AddAllocation(this->m_Id, TrackingMode, ptr, uiSize, uiAlign,
plTime::Now() - fAllocationTime);
84template <
typename A, plAllocatorTrackingMode TrackingMode>
87 if constexpr (TrackingMode >= plAllocatorTrackingMode::AllocationStats)
89 plMemoryTracker::RemoveAllocation(this->m_Id, pPtr);
92 m_allocator.Deallocate(pPtr);
95template <
typename A, plAllocatorTrackingMode TrackingMode>
98 if constexpr (TrackingMode >= plAllocatorTrackingMode::AllocationStats)
100 return plMemoryTracker::GetAllocationInfo(this->m_Id, pPtr).m_uiSize;
108template <
typename A, plAllocatorTrackingMode TrackingMode>
114template <
typename A, plAllocatorTrackingMode TrackingMode>
117 if constexpr (TrackingMode >= plAllocatorTrackingMode::Basics)
119 return plMemoryTracker::GetAllocatorStats(this->m_Id);
127template <
typename A, plAllocatorTrackingMode TrackingMode>
130 return m_allocator.GetParent();
133template <
typename A, plAllocatorTrackingMode TrackingMode,
bool HasReallocate>
135 : plAllocatorImpl<A, TrackingMode>(sName, pParent)
139template <
typename A, plAllocatorTrackingMode TrackingMode>
141 : plAllocatorImpl<A, TrackingMode>(sName, pParent)
145template <
typename A, plAllocatorTrackingMode TrackingMode>
148 if constexpr (TrackingMode >= plAllocatorTrackingMode::AllocationStats)
150 plMemoryTracker::RemoveAllocation(this->m_Id, pPtr);
155 void* pNewMem = this->m_allocator.Reallocate(pPtr, uiCurrentSize, uiNewSize, uiAlign);
157 if constexpr (TrackingMode >= plAllocatorTrackingMode::AllocationStats)
159 plMemoryTracker::AddAllocation(this->m_Id, TrackingMode, pNewMem, uiNewSize, uiAlign,
plTime::Now() - fAllocationTime);