ObjectAlloc: port ObjectAlloc.cpp and HeapUsage.cpp
ObjectAlloc.cpp (0x4D2AA0-0x4D36C0) and HeapUsage.cpp (0x4D2780-0x4D2AA0). CObjectHeap moves from _Triage to IObjectAlloc.h, where 12340's inline destructor puts it (IObjectAlloc.h line 30 in the SMemFree calls). stpl.h: TSFixedArray gets its copy constructor (clear, then Set), which the CObjectHeapList copy at 0x4D3410 proves; ReallocAndClearData is out of line at 0x4D2E90; new template instances added to the OFFSET lists. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -102,6 +102,7 @@ template <class T>
|
||||
class TSFixedArray : public TSBaseArray<T> {
|
||||
public:
|
||||
TSFixedArray();
|
||||
TSFixedArray(const TSFixedArray<T>& source);
|
||||
~TSFixedArray();
|
||||
TSFixedArray<T>& operator=(const TSFixedArray<T>& source);
|
||||
void Clear();
|
||||
@@ -634,8 +635,17 @@ TSFixedArray<T>::TSFixedArray() {
|
||||
this->m_data = nullptr;
|
||||
}
|
||||
|
||||
// INLINED
|
||||
template <class T>
|
||||
TSFixedArray<T>::TSFixedArray(const TSFixedArray<T>& source) {
|
||||
this->m_alloc = 0;
|
||||
this->m_count = 0;
|
||||
this->m_data = nullptr;
|
||||
this->Set(source.m_count, source.m_data);
|
||||
}
|
||||
|
||||
// VERIFY: 0f3f0aeb manual
|
||||
// OFFSET: [0x0047C630, 0x0047C6C0, 0x00490BE0, 0x004967E0, 0x004B74F0, 0x004BAFD0, 0x004BC2F0, 0x004BC380, 0x004BE2D0, 0x004C0260, 0x004C9520, 0x004CA720, 0x004CC6F0, 0x004CC780, 0x004CDDD0, 0x004CF070, 0x004D4E10, 0x004F31F0, 0x005032A0, 0x00503330, 0x005033C0, 0x00503450, 0x005053E0, 0x00527BF0, 0x00527C80, 0x00527E70, 0x0052F100, 0x0053F160, 0x00548B70, 0x00558C50, 0x00558CE0, 0x0055F560, 0x0055F5F0, 0x0055F680, 0x0055F710, 0x0055F7A0, 0x00566700, 0x00575F60, 0x005920F0, 0x005B4DE0, 0x005B4E70, 0x005BE830, 0x005BE8C0, 0x005C7290, 0x005C7320, 0x005D24E0, 0x005F03B0, 0x005F3E20, 0x005F5AD0, 0x005F5B60, 0x005F5BF0, 0x005FCB80, 0x00617AA0, 0x00617B30, 0x00617BC0, 0x0066E830, 0x0066E8C0, 0x0066E950, 0x0066E9E0, 0x0066EA70, 0x0066EB00, 0x0066EB90, 0x0066EC20, 0x0066ECB0, 0x0066ED40, 0x0066EDD0, 0x0066EE60, 0x0066EEF0, 0x0066EF80, 0x0066F010, 0x0066F0A0, 0x0066F130, 0x0066F1C0, 0x0066F250, 0x0066F2E0, 0x0066F370, 0x0066F400, 0x0066F490, 0x0066F520, 0x0066F5B0, 0x0066F640, 0x0066F6D0, 0x0066F760, 0x0066F7F0, 0x0066F880, 0x006881A0, 0x006BBE30, 0x006BEE90, 0x006C2650, 0x006C2AC0, 0x006C2B50, 0x006C8380, 0x006E4EB0, 0x006E4F40, 0x006F2C50, 0x006F2CE0, 0x006F2D70, 0x006F2E00, 0x006F2E90, 0x006F2F20, 0x006F2FB0, 0x00709AA0, 0x00709B30, 0x0072FFC0, 0x007675F0, 0x007685D0, 0x00776AD0, 0x007B04D0, 0x007B5DF0, 0x007C0B40, 0x007C0BD0, 0x007DD360, 0x007DD3F0, 0x007E01C0, 0x007F2A20, 0x007F4ED0, 0x00804EF0, 0x00804F80, 0x008109F0, 0x00810A80, 0x00810B10, 0x00812BC0, 0x00812C50, 0x0081A620, 0x00848800, 0x0084B570, 0x00876550, 0x00877760, 0x0087B0F0]
|
||||
// OFFSET: [0x0047C630, 0x0047C6C0, 0x00490BE0, 0x004967E0, 0x004B74F0, 0x004BAFD0, 0x004BC2F0, 0x004BC380, 0x004BE2D0, 0x004C0260, 0x004C9520, 0x004CA720, 0x004CC6F0, 0x004CC780, 0x004CDDD0, 0x004CF070, 0x004D3130, 0x004D33C0, 0x004D4E10, 0x004F31F0, 0x005032A0, 0x00503330, 0x005033C0, 0x00503450, 0x005053E0, 0x00527BF0, 0x00527C80, 0x00527E70, 0x0052F100, 0x0053F160, 0x00548B70, 0x00558C50, 0x00558CE0, 0x0055F560, 0x0055F5F0, 0x0055F680, 0x0055F710, 0x0055F7A0, 0x00566700, 0x00575F60, 0x005920F0, 0x005B4DE0, 0x005B4E70, 0x005BE830, 0x005BE8C0, 0x005C7290, 0x005C7320, 0x005D24E0, 0x005F03B0, 0x005F3E20, 0x005F5AD0, 0x005F5B60, 0x005F5BF0, 0x005FCB80, 0x00617AA0, 0x00617B30, 0x00617BC0, 0x0066E830, 0x0066E8C0, 0x0066E950, 0x0066E9E0, 0x0066EA70, 0x0066EB00, 0x0066EB90, 0x0066EC20, 0x0066ECB0, 0x0066ED40, 0x0066EDD0, 0x0066EE60, 0x0066EEF0, 0x0066EF80, 0x0066F010, 0x0066F0A0, 0x0066F130, 0x0066F1C0, 0x0066F250, 0x0066F2E0, 0x0066F370, 0x0066F400, 0x0066F490, 0x0066F520, 0x0066F5B0, 0x0066F640, 0x0066F6D0, 0x0066F760, 0x0066F7F0, 0x0066F880, 0x006881A0, 0x006BBE30, 0x006BEE90, 0x006C2650, 0x006C2AC0, 0x006C2B50, 0x006C8380, 0x006E4EB0, 0x006E4F40, 0x006F2C50, 0x006F2CE0, 0x006F2D70, 0x006F2E00, 0x006F2E90, 0x006F2F20, 0x006F2FB0, 0x00709AA0, 0x00709B30, 0x0072FFC0, 0x007675F0, 0x007685D0, 0x00776AD0, 0x007B04D0, 0x007B5DF0, 0x007C0B40, 0x007C0BD0, 0x007DD360, 0x007DD3F0, 0x007E01C0, 0x007F2A20, 0x007F4ED0, 0x00804EF0, 0x00804F80, 0x008109F0, 0x00810A80, 0x00810B10, 0x00812BC0, 0x00812C50, 0x0081A620, 0x00848800, 0x0084B570, 0x00876550, 0x00877760, 0x0087B0F0]
|
||||
template <class T>
|
||||
TSFixedArray<T>::~TSFixedArray() {
|
||||
for (uint32_t i = 0; i < this->m_count; i++) {
|
||||
@@ -657,7 +667,8 @@ void TSFixedArray<T>::Clear() {
|
||||
this->m_data = nullptr;
|
||||
}
|
||||
|
||||
// INLINED
|
||||
// VERIFY: de17895f manual
|
||||
// OFFSET: 0x004D2E90
|
||||
template <class T>
|
||||
void TSFixedArray<T>::ReallocAndClearData(uint32_t count) {
|
||||
for (uint32_t i = 0; i < this->m_count; i++) {
|
||||
@@ -703,7 +714,7 @@ void TSFixedArray<T>::ReallocData(uint32_t count) {
|
||||
}
|
||||
|
||||
// VERIFY: 3666e861 manual
|
||||
// OFFSET: [0x00409470, 0x004C4B10, 0x0056B7C0, 0x0058EB60, 0x0058EBD0, 0x00591250, 0x005912C0, 0x005C5F00, 0x005E0800, 0x005EF6A0, 0x006EAAB0, 0x006FF5C0, 0x006FF630, 0x00700C80, 0x0077AC80, 0x007F8240, 0x0097FE80]
|
||||
// OFFSET: [0x00409470, 0x004C4B10, 0x004D3180, 0x0056B7C0, 0x0058EB60, 0x0058EBD0, 0x00591250, 0x005912C0, 0x005C5F00, 0x005E0800, 0x005EF6A0, 0x006EAAB0, 0x006FF5C0, 0x006FF630, 0x00700C80, 0x0077AC80, 0x007F8240, 0x0097FE80]
|
||||
template <class T>
|
||||
void TSFixedArray<T>::Set(uint32_t count, const T* data) {
|
||||
this->ReallocAndClearData(count);
|
||||
@@ -854,7 +865,7 @@ void TSGrowableArray<T>::GrowToFit(uint32_t index, int32_t zero) {
|
||||
}
|
||||
|
||||
// VERIFY: 910046a1 auto
|
||||
// OFFSET: [0x00405970, 0x00409410, 0x0047DE50, 0x004C69F0, 0x004CEBE0, 0x004D31E0, 0x004E3760, 0x00500F60, 0x005221D0, 0x00565420, 0x00579AD0, 0x0057F670, 0x0058FEF0, 0x005916F0, 0x00591890, 0x005C6480, 0x00615660, 0x006850E0, 0x00685130, 0x006851D0, 0x0068A030, 0x0068A090, 0x006B2A40, 0x006DEC70, 0x007761E0, 0x007CD1D0, 0x007E6E50, 0x007F0CC0, 0x007F4450, 0x00821670, 0x0082DB70, 0x0086D180, 0x00870550, 0x00879900, 0x008BFE30, 0x008C6DE0, 0x008C6E60, 0x00968330, 0x00980FB0]
|
||||
// OFFSET: [0x00405970, 0x00409410, 0x0047DE50, 0x004C69F0, 0x004CEBE0, 0x004D31E0, 0x004D35C0, 0x004E3760, 0x00500F60, 0x005221D0, 0x00565420, 0x00579AD0, 0x0057F670, 0x0058FEF0, 0x005916F0, 0x00591890, 0x005C6480, 0x00615660, 0x006850E0, 0x00685130, 0x006851D0, 0x0068A030, 0x0068A090, 0x006B2A40, 0x006DEC70, 0x007761E0, 0x007CD1D0, 0x007E6E50, 0x007F0CC0, 0x007F4450, 0x00821670, 0x0082DB70, 0x0086D180, 0x00870550, 0x00879900, 0x008BFE30, 0x008C6DE0, 0x008C6E60, 0x00968330, 0x00980FB0]
|
||||
template <class T>
|
||||
T* TSGrowableArray<T>::New() {
|
||||
uint32_t newcount = this->m_count + 1;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "WoW/Source/ObjectAlloc/HeapUsage.h"
|
||||
#include "Engine/Source/ConsoleBase/ConsoleCommand.h"
|
||||
#include "Engine/Source/ConsoleBase/ConsoleVar.h"
|
||||
#include "Engine/Source/ConsoleBase/IConsole.h"
|
||||
#include "Engine/Source/Storm/H/storm.h"
|
||||
#include "WoW/Source/ObjectAlloc/ObjectAlloc.h"
|
||||
|
||||
// STATIC: 0x00B4AFBC
|
||||
static CVar* s_cvHeapAllocTracking;
|
||||
|
||||
// VERIFY: 6d10baa8 manual
|
||||
// OFFSET: 0x004D2780
|
||||
static bool ChangeHeapAllocTracking(CVar* var, const char* oldValue, const char* value, void* arg) {
|
||||
if (SStrToInt(value)) {
|
||||
SMemSetDebugFlags(SMEM_DEBUG_HEAPTRACKING, SMEM_DEBUG_HEAPTRACKING);
|
||||
ConsoleWrite("Heap tracking switched ON", DEFAULT_COLOR);
|
||||
} else {
|
||||
SMemSetDebugFlags(0, SMEM_DEBUG_HEAPTRACKING);
|
||||
ConsoleWrite("Heap tracking switched OFF", DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// VERIFY: 28c3bf02 auto
|
||||
// OFFSET: 0x004D27D0
|
||||
void HeapUsageDestroy() {
|
||||
ConsoleCommandUnregister("HeapUsage");
|
||||
}
|
||||
|
||||
// VERIFY: ac858bec manual
|
||||
// OFFSET: 0x004D27E0
|
||||
static int32_t HeapUsage(const char* command, const char* arguments) {
|
||||
char buffer[50000];
|
||||
char line[2048];
|
||||
|
||||
OBJALLOCGLOBALS* globals = GetObjAllocGlobals();
|
||||
uint32_t count = globals->objects.Count();
|
||||
uint32_t objectBytes = 0;
|
||||
uint32_t heapBytes = 0;
|
||||
char* str = buffer + SStrPrintf(buffer, sizeof(buffer), "%u Heaps in use:\n", count);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
CObjectHeapList& list = globals->objects[i];
|
||||
list.TotalHeaps();
|
||||
|
||||
uint32_t numAllocs = list.m_numAllocs >= 0xFFFFFFFF ? 0xFFFFFFFF : static_cast<uint32_t>(list.m_numAllocs);
|
||||
uint32_t totalBytes = list.TotalHeaps() * list.m_objSize * list.m_objsPerBlock;
|
||||
uint32_t usedBytes = list.BlocksAllocated() * list.m_objSize;
|
||||
|
||||
str += SStrPrintf(str, line - str, " \"%24s\" %3u blocks, %5u objs per block (%6u bytes per obj): %6u objs allocated (%3d%%) - Total bytes: %8.3fMb (%8.3fMb), Total Allocs: %d\n", list.m_heapName, list.TotalHeaps(), list.m_objsPerBlock, list.m_objSize, list.BlocksAllocated(), list.PercentUsed(), usedBytes * 0.00000095367432f, totalBytes * 0.00000095367432f, numAllocs);
|
||||
|
||||
objectBytes += globals->objects[i].m_objSize * globals->objects[i].BlocksAllocated();
|
||||
heapBytes += globals->objects[i].TotalHeaps() * globals->objects[i].m_objSize * globals->objects[i].m_objsPerBlock;
|
||||
}
|
||||
|
||||
SStrPrintf(str, line - str, "%4.3fMb total object bytes used, %4.3fMb bytes allocated for heaps\n", objectBytes * 0.00000095367432f, heapBytes * 0.00000095367432f);
|
||||
ReleaseObjAllocGlobals();
|
||||
|
||||
char* dest = line;
|
||||
|
||||
for (const char* src = buffer; *src; src++) {
|
||||
if (*src == '\n') {
|
||||
*dest = '\0';
|
||||
ConsoleWrite(line, DEFAULT_COLOR);
|
||||
dest = line;
|
||||
} else if (dest < line + sizeof(line) - 1) {
|
||||
*dest++ = *src;
|
||||
}
|
||||
}
|
||||
|
||||
if (dest != line) {
|
||||
ConsoleWrite(line, DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t MemUsage(const char* command, const char* arguments) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t HeapUsage2(const char* command, const char* arguments) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// VERIFY: 267b1512 auto
|
||||
// OFFSET: 0x004D2A30
|
||||
void HeapUsageInitialize() {
|
||||
ConsoleCommandRegister("HeapUsage", HeapUsage, CATEGORY_GAME, nullptr);
|
||||
ConsoleCommandRegister("MemUsage", MemUsage, CATEGORY_GAME, nullptr);
|
||||
ConsoleCommandRegister("HeapUsage2", HeapUsage2, CATEGORY_GAME, nullptr);
|
||||
s_cvHeapAllocTracking = CVar::Register("heapAllocTracking", "Enables/disables allocation tracking & dumping in SMemMalloc", 0, "1", ChangeHeapAllocTracking, CATEGORY_GAME, false, nullptr, false);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef WOW_SOURCE_OBJECTALLOC_HEAPUSAGE_H
|
||||
#define WOW_SOURCE_OBJECTALLOC_HEAPUSAGE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
void HeapUsageDestroy();
|
||||
void HeapUsageInitialize();
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,22 @@
|
||||
#ifndef WOW_SOURCE_OBJECTALLOC_IOBJECTALLOC_H
|
||||
#define WOW_SOURCE_OBJECTALLOC_IOBJECTALLOC_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class CObjectHeap {
|
||||
public:
|
||||
/* 0000 */ void* m_obj;
|
||||
/* 0004 */ uint32_t* m_indexStack;
|
||||
/* 0008 */ uint32_t m_allocated;
|
||||
|
||||
CObjectHeap();
|
||||
CObjectHeap(const CObjectHeap& source);
|
||||
~CObjectHeap();
|
||||
bool Allocate(uint32_t objSize, uint32_t count, const char* name);
|
||||
void Delete(uint32_t index, uint32_t objSize, uint32_t count);
|
||||
int32_t New(uint32_t objSize, uint32_t count, uint32_t* index, const char* name, void** ptr, bool zero);
|
||||
void* Ptr(uint32_t index, uint32_t objSize, uint32_t count);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1 +1,393 @@
|
||||
#include "ObjectAlloc.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include "WoW/Source/ObjectAlloc/ObjectAlloc.h"
|
||||
#include "Engine/Source/Storm/H/storm.h"
|
||||
#include "Engine/Source/Storm/Source/SLock.h"
|
||||
|
||||
// STATIC: 0x00B4AFC0
|
||||
static OBJALLOCGLOBALS s_globals;
|
||||
|
||||
// STATIC: 0x00B4AFD0
|
||||
static SCritSect s_globalsLock;
|
||||
|
||||
// INLINED
|
||||
CObjectHeap::CObjectHeap() {
|
||||
this->m_obj = nullptr;
|
||||
this->m_indexStack = nullptr;
|
||||
this->m_allocated = 0;
|
||||
}
|
||||
|
||||
// INLINED
|
||||
CObjectHeap::CObjectHeap(const CObjectHeap& source) {
|
||||
this->m_obj = source.m_obj;
|
||||
this->m_indexStack = source.m_indexStack;
|
||||
const_cast<CObjectHeap&>(source).m_obj = nullptr;
|
||||
const_cast<CObjectHeap&>(source).m_indexStack = nullptr;
|
||||
this->m_allocated = source.m_allocated;
|
||||
}
|
||||
|
||||
// INLINED
|
||||
CObjectHeap::~CObjectHeap() {
|
||||
if (this->m_obj) {
|
||||
SMemFree(this->m_obj, __FILE__, __LINE__, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// INLINED
|
||||
void CObjectHeap::Delete(uint32_t index, uint32_t objSize, uint32_t count) {
|
||||
if (this->m_allocated && this->m_indexStack) {
|
||||
this->m_indexStack[--this->m_allocated] = index;
|
||||
}
|
||||
}
|
||||
|
||||
// INLINED
|
||||
void* CObjectHeap::Ptr(uint32_t index, uint32_t objSize, uint32_t count) {
|
||||
return static_cast<char*>(this->m_obj) + index * objSize;
|
||||
}
|
||||
|
||||
// INLINED
|
||||
CObjectHeapList::CObjectHeapList() {
|
||||
this->m_objSize = 0;
|
||||
this->m_objsPerBlock = 128;
|
||||
this->m_numFullHeaps = 0;
|
||||
this->m_hasEmptyHeaps = 0;
|
||||
this->m_deleteCount = 0;
|
||||
this->m_fullestHeap = 0;
|
||||
this->m_numAllocs = 0;
|
||||
this->m_uint80 = 0;
|
||||
this->m_freeEmptyHeaps = 1;
|
||||
}
|
||||
|
||||
// VERIFY: 1ee37614 manual
|
||||
// OFFSET: 0x004D2AA0
|
||||
bool CObjectHeap::Allocate(uint32_t objSize, uint32_t count, const char* name) {
|
||||
this->m_obj = SMemAlloc(count * (objSize + sizeof(uint32_t)), name, 0, 0x2000000);
|
||||
|
||||
if (!this->m_obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->m_indexStack = reinterpret_cast<uint32_t*>(static_cast<char*>(this->m_obj) + count * objSize);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
this->m_indexStack[i] = i;
|
||||
}
|
||||
|
||||
this->m_allocated = 0;
|
||||
|
||||
return this->m_obj != nullptr;
|
||||
}
|
||||
|
||||
// VERIFY: 763163e1 auto
|
||||
// OFFSET: 0x004D2B10
|
||||
OBJALLOCGLOBALS* GetObjAllocGlobals() {
|
||||
s_globalsLock.Enter();
|
||||
|
||||
return &s_globals;
|
||||
}
|
||||
|
||||
// VERIFY: 3bafdd5f auto
|
||||
// OFFSET: 0x004D2B20
|
||||
void ReleaseObjAllocGlobals() {
|
||||
s_globalsLock.Leave();
|
||||
}
|
||||
|
||||
// VERIFY: 7d28d1a5 manual
|
||||
// OFFSET: 0x004D2B30
|
||||
void CObjectHeapList::FreeEmptyHeaps() {
|
||||
uint32_t count = this->m_heaps.Count();
|
||||
uint32_t allocated = 0;
|
||||
uint32_t capacity = 0;
|
||||
uint32_t emptyHeaps = 0;
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
CObjectHeap& heap = this->m_heaps[i];
|
||||
|
||||
if (heap.m_obj) {
|
||||
capacity += this->m_objsPerBlock;
|
||||
|
||||
if (heap.m_allocated) {
|
||||
allocated += heap.m_allocated;
|
||||
} else {
|
||||
emptyHeaps++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!emptyHeaps) {
|
||||
this->m_hasEmptyHeaps = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t threshold = allocated + ((3 * this->m_objsPerBlock) >> 1);
|
||||
|
||||
if (threshold < capacity) {
|
||||
for (uint32_t i = count; i > 0; i--) {
|
||||
if (threshold >= capacity || !emptyHeaps) {
|
||||
break;
|
||||
}
|
||||
|
||||
CObjectHeap& heap = this->m_heaps[i - 1];
|
||||
|
||||
if (heap.m_obj && !heap.m_allocated) {
|
||||
if (heap.m_obj) {
|
||||
SMemFree(heap.m_obj, __FILE__, __LINE__, 0);
|
||||
}
|
||||
|
||||
heap.m_obj = nullptr;
|
||||
capacity -= this->m_objsPerBlock;
|
||||
emptyHeaps--;
|
||||
this->m_deleteCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->m_hasEmptyHeaps = emptyHeaps != 0;
|
||||
}
|
||||
|
||||
// VERIFY: a5a75ca6 manual
|
||||
// OFFSET: 0x004D2C30
|
||||
uint32_t CObjectHeapList::BlocksAllocated() {
|
||||
uint32_t allocated = 0;
|
||||
|
||||
for (uint32_t i = 0; i < this->m_heaps.Count(); i++) {
|
||||
allocated += this->m_heaps[i].m_allocated;
|
||||
}
|
||||
|
||||
return allocated;
|
||||
}
|
||||
|
||||
// VERIFY: 8e6272eb auto
|
||||
// OFFSET: 0x004D2C50
|
||||
uint32_t CObjectHeapList::TotalHeaps() {
|
||||
uint32_t heaps = 0;
|
||||
|
||||
for (uint32_t i = 0; i < this->m_heaps.Count(); i++) {
|
||||
if (this->m_heaps[i].m_obj) {
|
||||
heaps++;
|
||||
}
|
||||
}
|
||||
|
||||
return heaps;
|
||||
}
|
||||
|
||||
// VERIFY: fdc6e79c auto
|
||||
// OFFSET: 0x004D2C80
|
||||
uint32_t CObjectHeapList::PercentUsed() {
|
||||
uint32_t capacity = 0;
|
||||
uint32_t allocated = 0;
|
||||
|
||||
for (uint32_t i = 0; i < this->m_heaps.Count(); i++) {
|
||||
if (this->m_heaps[i].m_obj) {
|
||||
capacity += this->m_objsPerBlock;
|
||||
allocated += this->m_heaps[i].m_allocated;
|
||||
}
|
||||
}
|
||||
|
||||
return capacity ? 100 * allocated / capacity : 0;
|
||||
}
|
||||
|
||||
// VERIFY: 6ca854e3 auto
|
||||
// OFFSET: 0x004D2CC0
|
||||
int32_t CObjectHeap::New(uint32_t objSize, uint32_t count, uint32_t* index, const char* name, void** ptr, bool zero) {
|
||||
if (this->m_allocated >= count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!this->m_obj) {
|
||||
this->Allocate(objSize, count, name);
|
||||
}
|
||||
|
||||
*index = this->m_indexStack[this->m_allocated++];
|
||||
|
||||
if (zero) {
|
||||
memset(static_cast<char*>(this->m_obj) + objSize * *index, 0, objSize);
|
||||
}
|
||||
|
||||
if (ptr) {
|
||||
*ptr = static_cast<char*>(this->m_obj) + objSize * *index;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// VERIFY: ec42cc99 auto
|
||||
// OFFSET: 0x004D2D40
|
||||
void* ObjectPtr(uint32_t heapId, uint32_t memHandle) {
|
||||
s_globalsLock.Enter();
|
||||
|
||||
CObjectHeapList& list = s_globals.objects[heapId];
|
||||
void* ptr = list.m_heaps[memHandle / list.m_objsPerBlock].Ptr(memHandle % list.m_objsPerBlock, list.m_objSize, list.m_objsPerBlock);
|
||||
|
||||
s_globalsLock.Leave();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// VERIFY: 1c705ebd manual
|
||||
// OFFSET: 0x004D2F00
|
||||
void CObjectHeapList::Delete(uint32_t index) {
|
||||
uint32_t heapIndex = index / this->m_objsPerBlock;
|
||||
CObjectHeap& heap = this->m_heaps[heapIndex];
|
||||
|
||||
if (heap.m_allocated == this->m_objsPerBlock) {
|
||||
this->m_numFullHeaps--;
|
||||
}
|
||||
|
||||
heap.Delete(index % this->m_objsPerBlock, this->m_objSize, this->m_objsPerBlock);
|
||||
|
||||
if (!this->m_freeEmptyHeaps) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->m_heaps[heapIndex].m_obj && !this->m_heaps[heapIndex].m_allocated) {
|
||||
this->m_hasEmptyHeaps = 1;
|
||||
}
|
||||
|
||||
if (this->m_hasEmptyHeaps && !(this->m_deleteCount++ & ((this->m_objsPerBlock - 1) >> 2))) {
|
||||
this->FreeEmptyHeaps();
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY: d5d48ee3 manual
|
||||
// OFFSET: 0x004D2F90
|
||||
static void HeapUse() {
|
||||
s_globalsLock.Enter();
|
||||
|
||||
uint32_t count = s_globals.objects.Count();
|
||||
uint32_t used = 0;
|
||||
uint32_t allocated = 0;
|
||||
|
||||
DebugLog("%u Heaps in use:\n", count);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
CObjectHeapList& list = s_globals.objects[i];
|
||||
|
||||
DebugLog(" \"%24s\" %3u blocks, %5u objs per block (%6u bytes per obj): %6u objs allocated (%2d%%)\n", list.m_heapName, list.TotalHeaps(), list.m_objsPerBlock, list.m_objSize, list.BlocksAllocated(), list.PercentUsed());
|
||||
|
||||
used += s_globals.objects[i].m_objSize * s_globals.objects[i].BlocksAllocated();
|
||||
allocated += s_globals.objects[i].TotalHeaps() * s_globals.objects[i].m_objSize * s_globals.objects[i].m_objsPerBlock;
|
||||
}
|
||||
|
||||
DebugLog("%u total object bytes used, %u bytes allocated for heaps\n", used, allocated);
|
||||
|
||||
s_globalsLock.Leave();
|
||||
}
|
||||
|
||||
// VERIFY: 816bb6c5 auto
|
||||
// OFFSET: 0x004D3100
|
||||
void ObjectFree(uint32_t heapId, uint32_t memHandle) {
|
||||
s_globalsLock.Enter();
|
||||
s_globals.objects[heapId].Delete(memHandle);
|
||||
s_globalsLock.Leave();
|
||||
}
|
||||
|
||||
// VERIFY: 862b80b0 manual
|
||||
// OFFSET: 0x004D3250
|
||||
int32_t CObjectHeapList::New(uint32_t* index, void** ptr, bool zero) {
|
||||
CObjectHeap* heap = nullptr;
|
||||
uint32_t count = this->m_heaps.Count();
|
||||
|
||||
if (this->m_fullestHeap < count && this->m_heaps[this->m_fullestHeap].m_allocated != this->m_objsPerBlock && this->m_heaps[this->m_fullestHeap].m_obj) {
|
||||
heap = &this->m_heaps[this->m_fullestHeap];
|
||||
} else if (count == this->m_numFullHeaps) {
|
||||
this->m_fullestHeap = count;
|
||||
heap = this->m_heaps.New();
|
||||
|
||||
if (!heap->Allocate(this->m_objSize, this->m_objsPerBlock, this->m_heapName)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (this->m_heaps[i].m_allocated != this->m_objsPerBlock) {
|
||||
this->m_fullestHeap = i;
|
||||
heap = &this->m_heaps[i];
|
||||
|
||||
if (heap->m_obj) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!heap->New(this->m_objSize, this->m_objsPerBlock, index, this->m_heapName, ptr, zero)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*index += this->m_fullestHeap * this->m_objsPerBlock;
|
||||
|
||||
if (heap->m_allocated == this->m_objsPerBlock) {
|
||||
this->m_numFullHeaps++;
|
||||
}
|
||||
|
||||
this->m_numAllocs++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// VERIFY: 5a8067f9 auto
|
||||
// OFFSET: 0x004D3330
|
||||
int32_t ObjectAlloc(uint32_t heapId, uint32_t* memHandle, void** objectPtr, bool zero) {
|
||||
if (!memHandle) {
|
||||
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*memHandle = 0;
|
||||
s_globalsLock.Enter();
|
||||
|
||||
if (heapId >= s_globals.objects.Count()) {
|
||||
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t handle;
|
||||
void* ptr;
|
||||
|
||||
if (!s_globals.objects[heapId].New(&handle, &ptr, zero)) {
|
||||
s_globalsLock.Leave();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (objectPtr) {
|
||||
*objectPtr = ptr;
|
||||
}
|
||||
|
||||
s_globalsLock.Leave();
|
||||
*memHandle = handle;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// VERIFY: 493549ac auto
|
||||
// OFFSET: 0x004D3580
|
||||
void ObjectAllocDestroy() {
|
||||
HeapUse();
|
||||
|
||||
s_globalsLock.Enter();
|
||||
s_globals.objects.Clear();
|
||||
s_globalsLock.Leave();
|
||||
}
|
||||
|
||||
// VERIFY: 739a3bb6 auto
|
||||
// OFFSET: 0x004D3650
|
||||
uint32_t ObjectAllocAddHeap(uint32_t objectSize, uint32_t objectsPerBlock, const char* name, bool freeEmptyHeaps) {
|
||||
if (!objectSize) {
|
||||
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s_globalsLock.Enter();
|
||||
|
||||
uint32_t heapId = s_globals.objects.Count();
|
||||
CObjectHeapList* list = s_globals.objects.New();
|
||||
list->m_objSize = objectSize;
|
||||
list->m_objsPerBlock = objectsPerBlock;
|
||||
SStrCopy(list->m_heapName, name, sizeof(list->m_heapName));
|
||||
list->m_freeEmptyHeaps = freeEmptyHeaps;
|
||||
|
||||
s_globalsLock.Leave();
|
||||
|
||||
return heapId;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "Engine/Source/Base/ObjectAlloc.h"
|
||||
#include "Engine/Source/Storm/H/stpl.h"
|
||||
|
||||
struct CObjectHeap;
|
||||
#include "WoW/Source/ObjectAlloc/IObjectAlloc.h"
|
||||
|
||||
class CObjectHeapList {
|
||||
public:
|
||||
@@ -14,14 +14,29 @@ class CObjectHeapList {
|
||||
/* 0014 */ uint32_t m_objsPerBlock;
|
||||
/* 0018 */ uint32_t m_numFullHeaps;
|
||||
/* 001C */ uint32_t m_hasEmptyHeaps;
|
||||
/* 0020 */ uint32_t m_uint20;
|
||||
/* 0020 */ uint32_t m_deleteCount;
|
||||
/* 0024 */ uint32_t m_fullestHeap;
|
||||
/* 0028 */ char m_heapName [80];
|
||||
/* 0078 */ uint32_t m_uint78;
|
||||
/* 007C */ uint32_t m_uint7C;
|
||||
/* 0028 */ char m_heapName[80];
|
||||
/* 0078 */ uint64_t m_numAllocs;
|
||||
/* 0080 */ uint32_t m_uint80;
|
||||
/* 0084 */ uint8_t m_freeEmptyHeaps;
|
||||
/* 0085 */ uint8_t unk_0085[3];
|
||||
|
||||
CObjectHeapList();
|
||||
uint32_t BlocksAllocated();
|
||||
void Delete(uint32_t index);
|
||||
void FreeEmptyHeaps();
|
||||
int32_t New(uint32_t* index, void** ptr, bool zero);
|
||||
uint32_t PercentUsed();
|
||||
uint32_t TotalHeaps();
|
||||
};
|
||||
|
||||
struct OBJALLOCGLOBALS {
|
||||
/* 0000 */ TSGrowableArray<CObjectHeapList> objects;
|
||||
};
|
||||
|
||||
OBJALLOCGLOBALS* GetObjAllocGlobals();
|
||||
void ObjectAllocDestroy();
|
||||
void* ObjectPtr(uint32_t heapId, uint32_t memHandle);
|
||||
void ReleaseObjAllocGlobals();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "CObjectHeap.h"
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef _TRIAGE_COBJECTHEAP_H
|
||||
#define _TRIAGE_COBJECTHEAP_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class CObjectHeap {
|
||||
public:
|
||||
/* 0000 */ void* m_obj;
|
||||
/* 0004 */ uint32_t* m_indexStack;
|
||||
/* 0008 */ uint32_t m_allocated;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user