2PL_ALWAYS_INLINE plAllocator::plAllocator() =
default;
4PL_ALWAYS_INLINE plAllocator::~plAllocator() =
default;
11 PL_FOUNDATION_DLL plUInt64
SafeMultiply64(plUInt64 a, plUInt64 b, plUInt64 c, plUInt64 d);
21 m_pInstance = pInstance;
22 m_pAllocator = pAllocator;
28 m_pInstance = other.m_pInstance;
29 m_pAllocator = other.m_pAllocator;
31 other.m_pInstance =
nullptr;
32 other.m_pAllocator =
nullptr;
43 PL_ALWAYS_INLINE
operator T*() {
return m_pInstance; }
45 PL_ALWAYS_INLINE T* operator->() {
return m_pInstance; }
47 T* m_pInstance =
nullptr;
54 return lhs.m_pInstance < rhs;
58 PL_ALWAYS_INLINE
bool operator<(T* lhs,
const NewInstance<T>& rhs)
60 return lhs < rhs.m_pInstance;
64 PL_FORCE_INLINE
void Delete(
plAllocator* pAllocator, T* pPtr)
69 pAllocator->Deallocate(pPtr);
74 PL_FORCE_INLINE T* CreateRawBuffer(
plAllocator* pAllocator,
size_t uiCount)
77 return static_cast<T*
>(pAllocator->
Allocate(
static_cast<size_t>(safeAllocationSize), PL_ALIGNMENT_OF(T)));
80 PL_FORCE_INLINE
void DeleteRawBuffer(
plAllocator* pAllocator,
void* pPtr)
84 pAllocator->Deallocate(pPtr);
91 T* buffer = CreateRawBuffer<T>(pAllocator, uiCount);
100 T* buffer = arrayPtr.
GetPtr();
101 if (buffer !=
nullptr)
104 pAllocator->Deallocate(buffer);
108 template <
typename T>
109 PL_FORCE_INLINE T* ExtendRawBuffer(T* pPtr,
plAllocator* pAllocator,
size_t uiCurrentCount,
size_t uiNewCount,
plTypeIsPod)
111 return (T*)pAllocator->Reallocate(pPtr, uiCurrentCount *
sizeof(T), uiNewCount *
sizeof(T), PL_ALIGNMENT_OF(T));
114 template <
typename T>
117 return (T*)pAllocator->Reallocate(pPtr, uiCurrentCount *
sizeof(T), uiNewCount *
sizeof(T), PL_ALIGNMENT_OF(T));
120 template <
typename T>
121 PL_FORCE_INLINE T* ExtendRawBuffer(T* pPtr,
plAllocator* pAllocator,
size_t uiCurrentCount,
size_t uiNewCount,
plTypeIsClass)
123 static_assert(!std::is_trivial<T>::value,
124 "POD type is treated as class. Use PL_DECLARE_POD_TYPE(YourClass) or PL_DEFINE_AS_POD_TYPE(ExternalClass) to mark it as POD.");
126 T* pNewMem = CreateRawBuffer<T>(pAllocator, uiNewCount);
128 DeleteRawBuffer(pAllocator, pPtr);
132 template <
typename T>
133 PL_FORCE_INLINE T* ExtendRawBuffer(T* pPtr,
plAllocator* pAllocator,
size_t uiCurrentCount,
size_t uiNewCount)
135 PL_ASSERT_DEV(uiCurrentCount < uiNewCount,
"Shrinking of a buffer is not implemented yet");
136 PL_ASSERT_DEV(!(uiCurrentCount == uiNewCount),
"Same size passed in twice.");
139 PL_ASSERT_DEV(uiCurrentCount == 0,
"current count must be 0 if ptr is nullptr");
141 return CreateRawBuffer<T>(pAllocator, uiNewCount);
143 return ExtendRawBuffer(pPtr, pAllocator, uiCurrentCount, uiNewCount,
plGetTypeClass<T>());
Base class for all memory allocators.
Definition Allocator.h:23
virtual void * Allocate(size_t uiSize, size_t uiAlign, plMemoryUtils::DestructorFunction destructorFunc=nullptr)=0
Interface, do not use this directly, always use the new/delete macros below.
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
PL_ALWAYS_INLINE plUInt32 GetCount() const
Returns the number of elements in the array.
Definition ArrayPtr.h:142
PL_ALWAYS_INLINE PointerType GetPtr() const
Returns the pointer to the array.
Definition ArrayPtr.h:118
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...
static void Construct(T *pDestination, size_t uiCount=1)
Constructs uiCount objects of type T in a raw buffer at pDestination.
static void Destruct(T *pDestination, size_t uiCount=1)
Destructs uiCount objects of type T at pDestination.
This namespace provides common math-functionality as functions.
Definition Constants.h:6
PL_FOUNDATION_DLL plUInt64 SafeMultiply64(plUInt64 a, plUInt64 b, plUInt64 c=1, plUInt64 d=1)
returns a * b. If an overflow happens, the program is terminated.
Definition Math.cpp:200
If there is an % operator which takes a plTypeIsMemRelocatable and returns a CompileTimeTrueType T is...
Definition TypeTraits.h:67
Definition Allocator_inl.h:18
Type traits.
Definition TypeTraits.h:12