UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
Memory.h
1#pragma once
2#include <UnCompute/Memory/Ptr.h>
3#include <UnCompute/Memory/SystemAllocator.h>
4
5namespace UN
6{
20 template<class T, class TAllocator, class... Args>
21 inline T* AllocateObjectEx(TAllocator* pAllocator, Args&&... args)
22 {
23 USize counterSize = AlignUp(sizeof(ReferenceCounter), alignof(T));
24 USize wholeSize = sizeof(T) + counterSize;
25
26 auto* ptr = static_cast<UInt8*>(pAllocator->Allocate(wholeSize, alignof(T)));
27 auto* counter = new (ptr) ReferenceCounter(pAllocator);
28
29 T* object = new (ptr + counterSize) T(std::forward<Args>(args)...);
30 object->AttachRefCounter(counter);
31 return object;
32 }
33
45 template<class T, class... Args>
46 inline T* AllocateObject(Args&&... args)
47 {
48 return AllocateObjectEx<T, SystemAllocator>(SystemAllocator::Get(), std::forward<Args>(args)...);
49 }
50} // namespace UN
static SystemAllocator * Get()
Get global static instance of the system allocator.
Definition: SystemAllocator.h:17