2#include <UnCompute/Memory/Ptr.h>
3#include <UnCompute/Memory/SystemAllocator.h>
20 template<
class T,
class TAllocator,
class... Args>
21 inline T* AllocateObjectEx(TAllocator* pAllocator, Args&&... args)
23 USize counterSize = AlignUp(
sizeof(ReferenceCounter),
alignof(T));
24 USize wholeSize =
sizeof(T) + counterSize;
26 auto* ptr =
static_cast<UInt8*
>(pAllocator->Allocate(wholeSize,
alignof(T)));
27 auto* counter =
new (ptr) ReferenceCounter(pAllocator);
29 T*
object =
new (ptr + counterSize) T(std::forward<Args>(args)...);
30 object->AttachRefCounter(counter);
45 template<
class T,
class... Args>
46 inline T* AllocateObject(Args&&... args)
48 return AllocateObjectEx<T, SystemAllocator>(
SystemAllocator::Get(), std::forward<Args>(args)...);
static SystemAllocator * Get()
Get global static instance of the system allocator.
Definition: SystemAllocator.h:17