[+] Heap::Clone(Heap *[, ...])

This commit is contained in:
Reece Wilson 2024-07-15 00:16:13 +01:00
parent ced9e0be17
commit 8df3f6970b

View File

@ -9,6 +9,13 @@
namespace Aurora::Memory
{
struct Heap;
namespace detail
{
inline AuSPtr<AuUInt8> AllocateArray(Heap *pHeap, AuUInt uLength, AuUInt32 uAlignment);
}
struct MemoryControlBlock
{
// Free-after-use mitigator: ensures a non-zero flag is kept whilst other memory views are present
@ -392,6 +399,19 @@ namespace Aurora::Memory
return MemoryView(MemoryView(pData.get(), uLength), pData);
}
MemoryView Clone(Heap *pHeap, AuUInt32 uAlignment = alignof(double)) const
{
auto uLength = this->uLength;
auto pData = detail::AllocateArray(uLength, uAlignment);
if (!pData)
{
return {};
}
AuMemcpy(pData.get(), this->pBase, uLength);
return MemoryView(MemoryView(pData.get(), uLength), pData);
}
bool TryCloneSelf(bool bResetOnFailure = true)
{
auto replacement = Clone();