4 : m_pAllocator(pAllocator)
10 : m_pAllocator(pAllocator)
12 m_pAllocator.
SetFlags(Storage::External);
19 : m_pAllocator(pAllocator)
26 : m_pAllocator(pAllocator)
28 *
this = std::move(other);
33 : m_pAllocator(pAllocator)
43 if (m_pAllocator.GetFlags() == Storage::Owned)
46 PL_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
49 this->m_uiCapacity = 0;
50 this->m_pElements =
nullptr;
65 if (this->m_pAllocator.GetPtr() == rhs.m_pAllocator.GetPtr() && rhs.m_pAllocator.GetFlags() == Storage::Owned)
67 if (this->m_pAllocator.GetFlags() == Storage::Owned)
70 PL_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
74 this->m_pAllocator.SetFlags(Storage::Owned);
77 this->m_uiCount = rhs.m_uiCount;
78 this->m_uiCapacity = rhs.m_uiCapacity;
79 this->m_pElements = rhs.m_pElements;
82 rhs.m_pElements =
nullptr;
89 this->Reserve(rhs.m_uiCount);
90 this->m_uiCount = rhs.m_uiCount;
93 this->GetElementsPtr(), rhs.GetElementsPtr() , rhs.m_uiCount);
102 if (this->m_pAllocator.GetFlags() == Storage::External && other.m_pAllocator.
GetFlags() == Storage::External)
104 constexpr plUInt32 InplaceStorageSize = 64;
106 struct alignas(PL_ALIGNMENT_OF(T)) Tmp
108 plUInt8 m_StaticData[InplaceStorageSize *
sizeof(T)];
111 const plUInt32 localSize = this->m_uiCount;
112 const plUInt32 otherLocalSize = other.
m_uiCount;
114 if (localSize <= InplaceStorageSize && otherLocalSize <= InplaceStorageSize && localSize <= other.
m_uiCapacity &&
115 otherLocalSize <= this->m_uiCapacity)
132 if (this->m_pAllocator.GetFlags() == Storage::External)
135 this->Reserve(this->m_uiCapacity + 1);
138 if (other.m_pAllocator.
GetFlags() == Storage::External)
154 if (this->m_pAllocator.GetFlags() == Storage::Owned && uiCapacity > this->m_uiCapacity)
156 this->m_pElements = PL_EXTEND_RAW_BUFFER(this->m_pAllocator, this->m_pElements, this->m_uiCount, uiCapacity);
160 T* pOldElements = GetElementsPtr();
162 T* pNewElements = PL_NEW_RAW_BUFFER(this->m_pAllocator, T, uiCapacity);
165 if (this->m_pAllocator.GetFlags() == Storage::Owned)
167 PL_DELETE_RAW_BUFFER(this->m_pAllocator, pOldElements);
171 this->m_pAllocator.SetFlags(Storage::Owned);
172 this->m_pElements = pNewElements;
175 this->m_uiCapacity = uiCapacity;
181 if (this->m_uiCapacity >= uiCapacity)
184 const plUInt64 uiCurCap64 =
static_cast<plUInt64
>(this->m_uiCapacity);
185 plUInt64 uiNewCapacity64 = uiCurCap64 + (uiCurCap64 / 2);
189 constexpr plUInt64 uiMaxCapacity = 0xFFFFFFFFllu - (CAPACITY_ALIGNMENT - 1);
194 uiNewCapacity64 = (uiNewCapacity64 + (CAPACITY_ALIGNMENT - 1)) & ~(CAPACITY_ALIGNMENT - 1);
196 PL_ASSERT_DEV(uiCapacity <= uiNewCapacity64,
"The requested capacity of {} elements exceeds the maximum possible capacity of {} elements.", uiCapacity, uiMaxCapacity);
198 SetCapacity(
static_cast<plUInt32
>(uiNewCapacity64 & 0xFFFFFFFF));
204 if (m_pAllocator.GetFlags() == Storage::External)
210 PL_DELETE_RAW_BUFFER(this->m_pAllocator, this->m_pElements);
211 this->m_uiCapacity = 0;
215 const plUInt32 uiNewCapacity = (this->m_uiCount + (CAPACITY_ALIGNMENT - 1)) & ~(CAPACITY_ALIGNMENT - 1);
216 if (this->m_uiCapacity != uiNewCapacity)
217 SetCapacity(uiNewCapacity);
224 return this->m_pElements;
230 return this->m_pElements;
236 if (this->m_pAllocator.GetFlags() == Storage::External)
239 return (plUInt64)this->m_uiCapacity * (plUInt64)
sizeof(T);
242template <
typename T,
typename A>
248template <
typename T,
typename A>
254template <
typename T,
typename A>
260template <
typename T,
typename A>
266template <
typename T,
typename A>
272template <
typename T,
typename A>
278template <
typename T,
typename A>
284template <
typename T,
typename A>
290template <
typename T,
typename A>
296template <
typename T,
typename A>
302template <
typename T,
typename A>
308template <
typename T,
typename A>
314template <
typename T,
typename AllocatorWrapper>
320template <
typename T,
typename AllocatorWrapper>
326template <
typename T,
typename AllocatorWrapper>
Base class for all memory allocators.
Definition Allocator.h:23
Base class for all array containers. Implements all the basic functionality that only requires a poin...
Definition ArrayBase.h:19
T * GetData()
Returns a pointer to the array data, or nullptr if the array is empty.
Definition ArrayBase_inl.h:423
plUInt32 m_uiCount
The number of elements used from the array.
Definition ArrayBase.h:203
plUInt32 m_uiCapacity
Definition ArrayBase.h:206
T * m_pElements
Definition ArrayBase.h:200
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Implementation of a dynamically growing array.
Definition DynamicArray.h:14
~plDynamicArrayBase()
Destructor.
Definition DynamicArray_inl.h:39
void Swap(plDynamicArrayBase< T > &other)
swaps the contents of this array with another one
Definition DynamicArray_inl.h:100
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition DynamicArray_inl.h:234
plDynamicArrayBase(plAllocator *pAllocator)
Creates an empty array. Does not allocate any data yet.
Definition DynamicArray_inl.h:3
void Compact()
Tries to compact the array to avoid wasting memory. The resulting capacity is at least 'GetCount' (no...
Definition DynamicArray_inl.h:202
void Reserve(plUInt32 uiCapacity)
Expands the array so it can at least store the given capacity.
Definition DynamicArray_inl.h:179
void operator=(const plDynamicArrayBase< T > &rhs)
Copies the data from some other contiguous array into this one.
Definition DynamicArray_inl.h:54
Definition DynamicArray.h:81
static void RelocateConstruct(T *pDestination, T *pSource, size_t uiCount=1)
Constructs uiCount objects of type T in a raw buffer at pDestination from an existing array of object...
plUInt8 GetFlags() const
Returns the flags value only.
Definition PointerWithFlags.h:66
void SetFlags(plUInt8 uiFlags)
Changes only the flags value. The given value must fit into the reserved bits.
Definition PointerWithFlags.h:73
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
PL_ALWAYS_INLINE void Swap(T &ref_f1, T &ref_f2)
Swaps the values in the two variables f1 and f2.
Definition Math_inl.h:224
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39