[+] std::pmr requirements
This commit is contained in:
parent
aa04b11a57
commit
7935159290
@ -9,6 +9,18 @@
|
||||
|
||||
namespace Aurora::Memory
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct AccessorICantEven
|
||||
{
|
||||
template <class T, class Z>
|
||||
cstatic void Set(const T &fuckCpp, Z that)
|
||||
{
|
||||
fuckCpp.pFuckCppRetardsFixYourWorthlessSpec2 = decltype(fuckCpp.pFuckCppRetardsFixYourWorthlessSpec2)(that);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct CppHeapWrapper
|
||||
{
|
||||
@ -66,10 +78,17 @@ namespace Aurora::Memory
|
||||
pFuckCppRetardsFixYourWorthlessSpec(pFuckCppRetardsFixYourWorthlessSpec)
|
||||
{ }
|
||||
|
||||
template <class T>
|
||||
inline CppHeapWrapper(const CppHeapWrapper<T> &fuckCpp)
|
||||
{
|
||||
this->pFuckCppRetardsFixYourWorthlessSpec = (CppHeapWrapper *)&fuckCpp;
|
||||
detail::AccessorICantEven::Set(fuckCpp, this);
|
||||
}
|
||||
|
||||
inline CppHeapWrapper(const CppHeapWrapper &fuckCpp)
|
||||
{
|
||||
this->pFuckCppRetardsFixYourWorthlessSpec = (CppHeapWrapper *)&fuckCpp;
|
||||
fuckCpp.pFuckCppRetardsFixYourWorthlessSpec2 = this;
|
||||
detail::AccessorICantEven::Set(fuckCpp, this);
|
||||
}
|
||||
|
||||
inline CppHeapWrapper(CppHeapWrapper &&fuckCpp)
|
||||
@ -102,54 +121,113 @@ namespace Aurora::Memory
|
||||
AU_DEF(CppHeapWrapper)
|
||||
AU_OPERATOR_COPY_MOVE(CppHeapWrapper)
|
||||
|
||||
constexpr void deallocate(const T *pType,
|
||||
const size_t count)
|
||||
void *allocate_bytes(std::size_t nbytes,
|
||||
std::size_t alignment = alignof(std::max_align_t))
|
||||
{
|
||||
this->GetHeapRaw()->Free((T *)pType);
|
||||
}
|
||||
|
||||
constexpr AU_ALLOC T *allocate(const size_t count)
|
||||
{
|
||||
if (!count)
|
||||
if (auto pRet = this->GetHeapRaw()->FAlloc(nbytes, alignment))
|
||||
{
|
||||
return nullptr;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
auto pData = this->GetHeapRaw()->FAlloc(count * sizeof(T), alignof(T));
|
||||
if (!pData)
|
||||
else
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return (T *)pData;
|
||||
}
|
||||
|
||||
void deallocate_bytes(void *p,
|
||||
std::size_t nbytes,
|
||||
std::size_t alignment = alignof(std::max_align_t)) noexcept
|
||||
{
|
||||
return this->GetHeapRaw()->Free(p);
|
||||
}
|
||||
|
||||
#if defined(AU_LANG_CPP_23)
|
||||
std::allocation_result<T *> allocate_at_least(const size_t count)
|
||||
{
|
||||
auto pThat = this->allocate(count);
|
||||
return { (T *)pThat, this->GetHeapRaw()->GetChunkSize(pThat) / sizeof(T) };
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class U, class... Args >
|
||||
void construct(U *p, Args&&... args)
|
||||
{
|
||||
if constexpr (AuIsClass_v<T>)
|
||||
if constexpr (AuIsClass_v<U>)
|
||||
{
|
||||
new ((void *)p) T(AuForward<Args &&>(args)...);
|
||||
new ((void *)p) U(AuForward<Args &&>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <class U, class... Args >
|
||||
void construct_at(U *p, Args&&... args)
|
||||
{
|
||||
if constexpr (AuIsClass_v<T>)
|
||||
if constexpr (AuIsClass_v<U>)
|
||||
{
|
||||
new ((void *)p) T(AuForward<Args &&>(args)...);
|
||||
new ((void *)p) U(AuForward<Args &&>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AU_LANG_CPP_23)
|
||||
constexpr std::allocation_result<T *> allocate_at_least(const size_t count)
|
||||
void deallocate(const T *pType,
|
||||
const size_t count) noexcept
|
||||
{
|
||||
auto pThat = this->allocate(count);
|
||||
return { (T *)pThat, this->GetHeapRaw()->GetChunkSize(pThat) / sizeof(T) };
|
||||
this->deallocate_bytes((void *)pType, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Heap> GetHeap()
|
||||
AU_ALLOC T *allocate(const size_t count)
|
||||
{
|
||||
if (!count)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (T *)this->allocate_bytes(count * sizeof(T), alignof(T));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
U *allocate_object(std::size_t n = 1)
|
||||
{
|
||||
return (U *)this->allocate_bytes(sizeof(U) * n, alignof(U));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void deallocate_object(U *p, std::size_t n = 1)
|
||||
{
|
||||
this->deallocate_bytes(p, 0, 0);
|
||||
}
|
||||
|
||||
template <class U, class... CtorArgs>
|
||||
U *new_object(CtorArgs&&... args)
|
||||
{
|
||||
U *p = this->allocate_object<U>();
|
||||
if constexpr (AuIsClass_v<U> &&
|
||||
!AuIsTriviallyConstructible_v<U, CtorArgs>)
|
||||
{
|
||||
try
|
||||
{
|
||||
this->construct(p, AuForward<CtorArgs>(args)...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
this->deallocate_object(p);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void delete_object(U *p)
|
||||
{
|
||||
if constexpr (AuIsClass_v<U> &&
|
||||
!AuIsTriviallyDestructible_v<U>)
|
||||
{
|
||||
p->~U();
|
||||
}
|
||||
|
||||
this->deallocate_object(p);
|
||||
}
|
||||
|
||||
std::shared_ptr<Heap> GetHeap() const
|
||||
{
|
||||
if (this->pFuckCppRetardsFixYourWorthlessSpec)
|
||||
{
|
||||
@ -165,7 +243,7 @@ namespace Aurora::Memory
|
||||
}
|
||||
}
|
||||
|
||||
Heap *GetHeapRaw()
|
||||
Heap *GetHeapRaw() const
|
||||
{
|
||||
if (this->pFuckCppRetardsFixYourWorthlessSpec)
|
||||
{
|
||||
@ -213,6 +291,16 @@ namespace Aurora::Memory
|
||||
}
|
||||
}
|
||||
|
||||
inline bool operator==(const CppHeapWrapper &heap)
|
||||
{
|
||||
return this->GetHeapRaw() == heap.GetHeapRaw();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool operator==(const CppHeapWrapper<T> &heap)
|
||||
{
|
||||
return this->GetHeapRaw() == heap.GetHeapRaw();
|
||||
}
|
||||
private:
|
||||
// should be sizeof(void *) * 4 = [pHeap, pControlBlock, pParent, pSingleThreadChild]
|
||||
// nor not. it doesnt matter.
|
||||
@ -224,5 +312,7 @@ namespace Aurora::Memory
|
||||
#endif
|
||||
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec {};
|
||||
mutable CppHeapWrapper *pFuckCppRetardsFixYourWorthlessSpec2 {};
|
||||
|
||||
friend struct detail::AccessorICantEven;
|
||||
};
|
||||
}
|
@ -54,9 +54,14 @@ namespace Aurora::Memory
|
||||
return _FAlloc(uLength, uAlignment);
|
||||
}
|
||||
|
||||
static void __Free(void *buffer)
|
||||
static void __Free(void *pHead)
|
||||
{
|
||||
_Free(buffer);
|
||||
_Free(pHead);
|
||||
}
|
||||
|
||||
static AuUInt __SizeOf(void *pHead)
|
||||
{
|
||||
return GetChunkSize(pHead);
|
||||
}
|
||||
|
||||
#if !defined(_CPPSHARP)
|
||||
|
Loading…
Reference in New Issue
Block a user