[*] Update behaviour of CppHeapWrapper to make it moron proof

This commit is contained in:
Reece Wilson 2024-08-07 19:48:15 +01:00
parent 9a855f36d0
commit b1e02c7e72
3 changed files with 43 additions and 12 deletions

View File

@ -141,7 +141,7 @@ namespace Aurora::Memory
return this->GetHeapRaw()->Free(p);
}
#if defined(AU_LANG_CPP_23)
#if defined(AU_LANG_CPP_23_)
std::allocation_result<T *> allocate_at_least(const size_t count)
{
auto pThat = this->allocate(count);
@ -217,6 +217,15 @@ namespace Aurora::Memory
this->deallocate_object(p);
}
bool IsInitialized() const
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
return bool(this->pHeap);
#else
return bool(this->spHeap);
#endif
}
std::shared_ptr<Heap> GetHeap() const
{
if (this->pFuckCppRetardsFixYourWorthlessSpec)
@ -235,22 +244,39 @@ namespace Aurora::Memory
Heap *GetHeapRaw() const
{
Heap *pRet {};
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
return this->pFuckCppRetardsFixYourWorthlessSpec->GetHeapRaw();
pRet = this->pFuckCppRetardsFixYourWorthlessSpec->GetHeapRaw();
}
else
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
return this->pHeap;
pRet = this->pHeap;
#else
return this->spHeap.get();
pRet = this->spHeap.get();
#endif
}
if (pRet)
{
return pRet;
}
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
return this->pHeap = __audetail::gDefaultDiscontiguousHeap;
#else
return (this->spHeap = __audetail::gDefaultDiscontiguousHeapShared).get();
#endif
}
void SetHeap(std::shared_ptr<Heap> pHeap)
{
if (this->IsInitialized())
{
return;
}
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
this->pFuckCppRetardsFixYourWorthlessSpec->SetHeap(pHeap);
@ -266,6 +292,10 @@ namespace Aurora::Memory
void SetHeapRaw(Heap *pHeap)
{
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
return;
}
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
this->pFuckCppRetardsFixYourWorthlessSpec->SetHeapRaw(pHeap);
@ -291,10 +321,10 @@ namespace Aurora::Memory
// should be sizeof(void *) * 4 = [pHeap, pControlBlock, pParent, pSingleThreadChild]
// nor not. it doesnt matter.
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
std::shared_ptr<void> spHeap;
Heap *pHeap {};
mutable std::shared_ptr<void> spHeap;
mutable Heap *pHeap {};
#else
std::shared_ptr<Heap> spHeap;
mutable std::shared_ptr<Heap> spHeap;
#endif
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec {};
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec2 {};

View File

@ -21,6 +21,12 @@ namespace Aurora::Memory
#include "HeapStats.hpp"
#include "Heap.hpp"
namespace __audetail
{
inline auto gDefaultDiscontiguousHeap = Aurora::Memory::GetDefaultDiscontiguousHeap();
inline auto gDefaultDiscontiguousHeapShared = Aurora::Memory::GetDefaultDiscontiguousHeapShared();
}
#include "Cache.hpp"
#include "SwapLock.hpp"
#include "Transition.hpp"

View File

@ -142,11 +142,6 @@ auto AuNullPointer()
return Aurora::Memory::Heap::NullUniquePointer<T>();
}
namespace __audetail
{
inline AuMemory::Heap *gDefaultDiscontiguousHeap = AuMemory::GetDefaultDiscontiguousHeap();
}
template <class T, class ...Args>
AuHUPOf_t<T> AuNewClassArrayUnique(AuUInt uElements, Args &&... fillCtr)
{