[*] shit spec by shit for brains phd boomers

This commit is contained in:
Reece Wilson 2024-03-24 23:56:23 +00:00
parent 1fa12f141f
commit 8a9c45c213

View File

@ -45,25 +45,67 @@ namespace Aurora::Memory
#endif
inline CppHeapWrapper(std::shared_ptr<Heap> pHeap) :
pHeap(pHeap)
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
spHeap(pHeap),
pHeap(pHeap.get())
#else
spHeap(pHeap)
#endif
{ }
inline CppHeapWrapper(Heap *pHeap, std::shared_ptr<void> pThat = {}) :
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
spHeap(pThat),
pHeap(pHeap)
#else
spHeap(AuSharedPointerFromShared(pHeap, pThat))
#endif
{ }
inline CppHeapWrapper(CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec) :
pFuckCppRetardsFixYourWorthlessSpec(pFuckCppRetardsFixYourWorthlessSpec)
{ }
inline CppHeapWrapper(const CppHeapWrapper &fuckCpp) :
pFuckCppRetardsFixYourWorthlessSpec((CppHeapWrapper *)&fuckCpp)
{ }
inline CppHeapWrapper(const CppHeapWrapper &fuckCpp)
{
this->pFuckCppRetardsFixYourWorthlessSpec = (CppHeapWrapper *)&fuckCpp;
fuckCpp.pFuckCppRetardsFixYourWorthlessSpec2 = this;
}
inline CppHeapWrapper(CppHeapWrapper &&fuckCpp)
{
if ((this->pFuckCppRetardsFixYourWorthlessSpec = fuckCpp.pFuckCppRetardsFixYourWorthlessSpec))
{
this->pFuckCppRetardsFixYourWorthlessSpec->pFuckCppRetardsFixYourWorthlessSpec2 = this;
}
fuckCpp.pFuckCppRetardsFixYourWorthlessSpec2 = fuckCpp.pFuckCppRetardsFixYourWorthlessSpec = nullptr;
}
inline ~CppHeapWrapper()
{
if (this->pFuckCppRetardsFixYourWorthlessSpec &&
this->pFuckCppRetardsFixYourWorthlessSpec->pFuckCppRetardsFixYourWorthlessSpec2 == this)
{
this->pFuckCppRetardsFixYourWorthlessSpec->pFuckCppRetardsFixYourWorthlessSpec2 = this->pFuckCppRetardsFixYourWorthlessSpec2;
}
if (this->pFuckCppRetardsFixYourWorthlessSpec2)
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
this->pFuckCppRetardsFixYourWorthlessSpec2->pHeap = this->pHeap;
#endif
this->pFuckCppRetardsFixYourWorthlessSpec2->spHeap = this->spHeap;
this->pFuckCppRetardsFixYourWorthlessSpec2->pFuckCppRetardsFixYourWorthlessSpec = this->pFuckCppRetardsFixYourWorthlessSpec;
this->pFuckCppRetardsFixYourWorthlessSpec2 = nullptr;
}
}
AU_MOVE(CppHeapWrapper)
AU_DEF(CppHeapWrapper)
AU_OPERATOR_COPY_MOVE(CppHeapWrapper)
constexpr void deallocate(const T *pType,
const size_t count)
{
this->GetHeap()->Free((T *)pType);
this->GetHeapRaw()->Free((T *)pType);
}
constexpr AU_ALLOC T *allocate(const size_t count)
@ -73,7 +115,7 @@ namespace Aurora::Memory
return nullptr;
}
auto pData = this->GetHeap()->FAlloc(count * sizeof(T), alignof(T));
auto pData = this->GetHeapRaw()->FAlloc(count * sizeof(T), alignof(T));
if (!pData)
{
throw std::bad_alloc();
@ -103,11 +145,11 @@ namespace Aurora::Memory
constexpr std::allocation_result<T *> allocate_at_least(const size_t count)
{
auto pThat = this->allocate(count);
return { (T *)pThat, this->GetHeap()->GetChunkSize(pThat) / sizeof(T) };
return { (T *)pThat, this->GetHeapRaw()->GetChunkSize(pThat) / sizeof(T) };
}
#endif
std::shared_ptr<Heap> &GetHeap()
std::shared_ptr<Heap> GetHeap()
{
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
@ -115,7 +157,27 @@ namespace Aurora::Memory
}
else
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
return AuSharedPointerFromShared(this->pHeap, this->spHeap);
#else
return this->spHeap;
#endif
}
}
Heap *GetHeapRaw()
{
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
return this->pFuckCppRetardsFixYourWorthlessSpec->GetHeapRaw();
}
else
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
return this->pHeap;
#else
return this->spHeap.get();
#endif
}
}
@ -127,12 +189,40 @@ namespace Aurora::Memory
}
else
{
this->spHeap = pHeap;
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
this->pHeap = pHeap.get();
#endif
}
}
void SetHeapRaw(Heap *pHeap)
{
if (this->pFuckCppRetardsFixYourWorthlessSpec)
{
this->pFuckCppRetardsFixYourWorthlessSpec->SetHeapRaw(pHeap);
}
else
{
#if defined(AU_NO_COMPRESS_CPPHEAP_WRAPPER)
AuResetMember(this->spHeap);
this->pHeap = pHeap;
#else
this->spHeap = AuUnsafeRaiiToShared(pHeap);
#endif
}
}
private:
std::shared_ptr<Heap> pHeap;
CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec {};
// 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 {};
#else
std::shared_ptr<Heap> spHeap;
#endif
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec {};
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec2 {};
};
}