diff --git a/Include/Aurora/Memory/CppHeapWrapper.hpp b/Include/Aurora/Memory/CppHeapWrapper.hpp index 47cf0a2e..b0985823 100644 --- a/Include/Aurora/Memory/CppHeapWrapper.hpp +++ b/Include/Aurora/Memory/CppHeapWrapper.hpp @@ -48,14 +48,22 @@ namespace Aurora::Memory pHeap(pHeap) { } - AU_COPY_MOVE_DEF(CppHeapWrapper) - std::shared_ptr pHeap; + inline CppHeapWrapper(CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec) : + pFuckCppRetardsFixYourWorthlessSpec(pFuckCppRetardsFixYourWorthlessSpec) + { } + + inline CppHeapWrapper(const CppHeapWrapper &fuckCpp) : + pFuckCppRetardsFixYourWorthlessSpec((CppHeapWrapper *)&fuckCpp) + { } + + AU_MOVE(CppHeapWrapper) + AU_DEF(CppHeapWrapper) constexpr void deallocate(const T *pType, const size_t count) { - this->pHeap->Free((T *)pType); + this->GetHeap()->Free((T *)pType); } constexpr AU_ALLOC T *allocate(const size_t count) @@ -65,7 +73,7 @@ namespace Aurora::Memory return nullptr; } - auto pData = this->pHeap->FAlloc(count, alignof(T)); + auto pData = this->GetHeap()->FAlloc(count * sizeof(T), alignof(T)); if (!pData) { throw std::bad_alloc(); @@ -73,12 +81,58 @@ namespace Aurora::Memory return (T *)pData; } + template + void construct(U *p, Args&&... args) + { + if constexpr (AuIsClass_v) + { + new ((void *)p) T(AuForward(args)...); + } + } + + template + void construct_at(U *p, Args&&... args) + { + if constexpr (AuIsClass_v) + { + new ((void *)p) T(AuForward(args)...); + } + } + #if defined(AU_LANG_CPP_23) constexpr std::allocation_result allocate_at_least(const size_t count) { auto pThat = this->allocate(count); - return { pThat, this->pHeap->GetChunkSize(pThat) }; + return { (T *)pThat, this->GetHeap()->GetChunkSize(pThat) / sizeof(T) }; } #endif + + std::shared_ptr &GetHeap() + { + if (this->pFuckCppRetardsFixYourWorthlessSpec) + { + return this->pFuckCppRetardsFixYourWorthlessSpec->GetHeap(); + } + else + { + return this->pHeap; + } + } + + void SetHeap(std::shared_ptr pHeap) + { + if (this->pFuckCppRetardsFixYourWorthlessSpec) + { + this->pFuckCppRetardsFixYourWorthlessSpec->SetHeap(pHeap); + } + else + { + this->pHeap = pHeap; + } + } + + private: + std::shared_ptr pHeap; + CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec {}; }; } \ No newline at end of file