diff --git a/Include/Aurora/Memory/Heap.hpp b/Include/Aurora/Memory/Heap.hpp index 2887b36b..5e0993d1 100644 --- a/Include/Aurora/Memory/Heap.hpp +++ b/Include/Aurora/Memory/Heap.hpp @@ -164,7 +164,7 @@ namespace Aurora::Memory pPtr = pThat->FAlloc(sizeof(T) + kAlignment, kAlignment); if (pPtr) { - new (pPtr + kAlignment) T(AuForward(args)...); + new (pPtr + kAlignment) T(AuForward(args)...); } } else @@ -204,7 +204,7 @@ namespace Aurora::Memory pPtr = pThat->FAlloc(sizeof(T) + kAlignment, kAlignment); if (pPtr) { - new (pPtr + kAlignment) T(AuForward(args)...); + new (pPtr + kAlignment) T(AuForward(args)...); } } else @@ -248,7 +248,7 @@ namespace Aurora::Memory { for (AU_ITERATE_N(i, uElements)) { - new (pPtr + kAlignment + (sizeof(T) * i)) T(AuForward(fillCtr)...); + new (pPtr + kAlignment + (sizeof(T) * i)) T(AuForward(fillCtr)...); } } } @@ -262,7 +262,7 @@ namespace Aurora::Memory static_assert(false); #else auto pElements = (T *)(pPtr + kAlignment); - std::fill(pElements, pElements + uElements, AuForward(fillCtr)...); + std::fill(pElements, pElements + uElements, AuForward(fillCtr)...); #endif } } @@ -309,7 +309,7 @@ namespace Aurora::Memory { for (AU_ITERATE_N(i, uElements)) { - new (pPtr + kAlignment + (sizeof(T) * i)) T(AuForward(fillCtr)...); + new (pPtr + kAlignment + (sizeof(T) * i)) T(AuForward(fillCtr)...); } } } @@ -323,7 +323,7 @@ namespace Aurora::Memory static_assert(false); #else auto pElements = (T *)(pPtr + kAlignment); - std::fill(pElements, pElements + uElements, AuForward(fillCtr)...); + std::fill(pElements, pElements + uElements, AuForward(fillCtr)...); #endif } } @@ -409,7 +409,18 @@ namespace Aurora::Memory /** Returns a heap interface backed by the default allocator */ - AUKN_SHARED_API(GetDefaultDiscontiguousHeap, Heap); + AUKN_SHARED_API(DefaultDiscontiguousHeap, Heap); + + inline Heap *GetDefaultDiscontiguousHeap() + { + return DefaultDiscontiguousHeapNew(); + } + + inline AuSPtr GetDefaultDiscontiguousHeapShared() + { + // Might not allocate the control block under some STLs, unlike DefaultDiscontiguousHeapSharedShared() which will generally always allocate a control block under most STLs + return AuUnsafeRaiiToShared(GetDefaultDiscontiguousHeap()); + } /** Allocates uLength amount of contiguous virtual memory diff --git a/Include/Aurora/RuntimeAliases.hpp b/Include/Aurora/RuntimeAliases.hpp index 4076d57a..592bb2d1 100644 --- a/Include/Aurora/RuntimeAliases.hpp +++ b/Include/Aurora/RuntimeAliases.hpp @@ -121,7 +121,37 @@ template using AuHUPOf_t = typename Aurora::Memory::Heap::HUPOf_t; template -static inline auto AuNullHeapPointer() +auto AuNullHeapPointer() { return Aurora::Memory::Heap::NullUniquePointer(); +} + +template +auto AuNullPointer() +{ + return Aurora::Memory::Heap::NullUniquePointer(); +} + +template +AuHUPOf_t AuNewClassArrayUnique(AuUInt uElements, Args &&... fillCtr) +{ + return Aurora::Memory::GetDefaultDiscontiguousHeap()->NewClassArrayUnique(uElements, AuForward(fillCtr)...); +} + +template +AuSPtr AuNewClassArray(AuUInt uElements, Args &&... fillCtr) +{ + return Aurora::Memory::GetDefaultDiscontiguousHeap()->NewClassArray(uElements, AuForward(fillCtr)...); +} + +template +AuHUPOf_t AuNewClassUnique(Args &&...args) +{ + return Aurora::Memory::GetDefaultDiscontiguousHeap()->NewClassUnique(AuForward(args)...); +} + +template +AuSPtr AuNewClass(Args &&...args) +{ + return Aurora::Memory::GetDefaultDiscontiguousHeap()->NewClass(AuForward(args)...); } \ No newline at end of file diff --git a/Source/IO/Net/AuNetAdapter.cpp b/Source/IO/Net/AuNetAdapter.cpp index 29c9ba64..18aa9e76 100644 --- a/Source/IO/Net/AuNetAdapter.cpp +++ b/Source/IO/Net/AuNetAdapter.cpp @@ -18,8 +18,6 @@ namespace Aurora::IO::Net IPAddress NetAdapter::GetAddress() { - AuMemory::GetDefaultDiscontiguousHeapShared()->NewClass(); - return this->address; } diff --git a/Source/Memory/DefaultHeap.cpp b/Source/Memory/DefaultHeap.cpp index 2facf3fb..03633659 100644 --- a/Source/Memory/DefaultHeap.cpp +++ b/Source/Memory/DefaultHeap.cpp @@ -97,10 +97,10 @@ namespace Aurora::Memory static DefaultHeap gDefaultAllocation; - AUKN_SYM Heap *GetDefaultDiscontiguousHeapNew() + AUKN_SYM Heap *DefaultDiscontiguousHeapNew() { return &gDefaultAllocation; } - AUKN_SYM void GetDefaultDiscontiguousHeapRelease(Heap * heap) {} + AUKN_SYM void DefaultDiscontiguousHeapRelease(Heap * heap) {} } \ No newline at end of file