Compare commits

...

2 Commits

5 changed files with 41 additions and 28 deletions

View File

@ -375,16 +375,6 @@ namespace Aurora::Memory
inline auline AuUInt Write(const void *buffer, AuUInt requestLength);
inline auline AuUInt Read(void *out, AuUInt requestedLength, bool peek = false);
inline auline AuUInt Write(const MemoryViewRead &read)
{
return Write(read.ptr, read.length);
}
inline auline AuUInt Read(const MemoryViewWrite &write)
{
return Read(write.ptr, write.length);
}
// String API
inline bool WriteString(AuROString string, EStringType type = EStringType::eStringDword, Locale::ECodePage codepage = Locale::ECodePage::eUTF8);
@ -411,13 +401,24 @@ namespace Aurora::Memory
T ReadChecked();
template<typename T>
bool Write(const T &in);
using ReadHack_t = AuConditional_t<AuIsSame_v<MemoryViewWrite, T>, AuUInt, bool>;
template<typename T>
bool Write(T &in);
using WriteHack_t = AuConditional_t<AuIsSame_v<MemoryViewRead, T>, AuUInt, bool>;
template<typename T>
bool Read(T &out);
WriteHack_t<T> Write(const T &in);
template<typename T>
WriteHack_t<T> Write(T &in);
template<typename T>
ReadHack_t<T> Read(T &out);
inline auline AuUInt Read(const MemoryViewWrite &write)
{
return Read(write.ptr, write.length);
}
template<typename T>
bool WriteTagged(const T &in);

View File

@ -150,11 +150,15 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Read(T &out)
ByteBuffer::ReadHack_t<T> ByteBuffer::Read(T &out)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasDeserializeBool<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewWrite>)
{
return Read(out.ptr, out.length);
}
else if constexpr (__detail::AuHasDeserializeBool<AuRemoveReference_t<T>>::type::value)
{
if (!out.Deserialize(*this))
{
@ -331,12 +335,16 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Write(T &in)
ByteBuffer::WriteHack_t<T> ByteBuffer::Write(T &in)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasSerializeBool<AuRemoveReference_t<T>>::type::value ||
__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewRead>)
{
return Write(in.ptr, in.length);
}
else if constexpr (__detail::AuHasSerializeBool<AuRemoveReference_t<T>>::type::value ||
__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
{
if (!in.Serialize(*this))
{
@ -366,11 +374,15 @@ namespace Aurora::Memory
}
template<typename T>
bool ByteBuffer::Write(const T &in)
ByteBuffer::WriteHack_t<T> ByteBuffer::Write(const T &in)
{
if constexpr (AuIsClass_v<T>)
{
if constexpr (__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
if constexpr (AuIsSame_v<T, MemoryViewRead>)
{
return Write(in.ptr, in.length);
}
else if constexpr (__detail::AuHasSerializeBool2<AuRemoveReference_t<T>>::type::value)
{
if (!in.Serialize(*this))
{

View File

@ -11,8 +11,8 @@ namespace Aurora::Memory
{
struct HeapStats
{
AuUInt64 qwBytesAllocatedLifetime {};
AuUInt64 qwBytesFreeLifetime {};
AuUInt uBytesAllocatedLifetime {};
AuUInt uBytesFreeLifetime {};
AuUInt uBytesCapacity {};

View File

@ -26,9 +26,9 @@ namespace Aurora::Memory
auto &stats = this->pHeap->GetStats();
this->stats.uBytesLiveCounter = this->uBytesAllocated;
this->stats.qwBytesAllocatedLifetime = this->uBytesLifetime;
this->stats.uBytesAllocatedLifetime = this->uBytesLifetime;
this->stats.uBytesPeakCounter = this->uBytesPeak;
this->stats.qwBytesFreeLifetime = this->uBytesFree;
this->stats.uBytesFreeLifetime = this->uBytesFree;
this->stats.uBytesCapacity = stats.uBytesCapacity;
}

View File

@ -13,10 +13,10 @@ namespace Aurora::Memory
std::shared_ptr<Heap> pHeap;
LeakFinderAlloc_f pAlloc;
LeakFinderFree_f pFree;
AuUInt64 uBytesAllocated {}; // current
AuUInt64 uBytesPeak {}; // max
AuUInt64 uBytesFree {}; // free count
AuUInt64 uBytesLifetime {}; // alloc count
AuUInt uBytesAllocated {}; // current
AuUInt uBytesPeak {}; // max
AuUInt uBytesFree {}; // free count
AuUInt uBytesLifetime {}; // alloc count
ProxyHeap(std::shared_ptr<Heap> pHeap,
LeakFinderAlloc_f pAlloc = {},