smartAutoFree

This commit is contained in:
Seeky 2020-12-26 11:35:40 +00:00
parent 7aaf7b20eb
commit 1e216a78f5
2 changed files with 35 additions and 7 deletions

View File

@ -15,7 +15,9 @@ typedef struct {
} MemWork;
typedef struct _SmartAllocation {
u8 unknown_0x0[0x14 - 0x0];
u8 unknown_0x0[0xe - 0x0];
u8 type;
u8 unknown_0xf[0x14 - 0xf];
struct _SmartAllocation * next;
struct _SmartAllocation * prev;
} SmartAllocation;
@ -26,8 +28,8 @@ typedef struct {
void * heapStart;
SmartAllocation allocations[SMART_ALLOCATION_MAX];
u32 heapSize;
u32 unknown_0xe008;
u32 unknown_0xe00c;
SmartAllocation * firstAllocated;
SmartAllocation * lastAllocated;
SmartAllocation * firstFree;
SmartAllocation * lastFree;
u32 unknown_0xe018;
@ -52,8 +54,8 @@ void memClear(s32 heapId); // 801a61e4
void * __memAlloc(s32 heapId, size_t size); // 801a626c
void __memFree(s32 heapId, void * ptr); // 801a62f0
void smartInit(); // 801a6300
// smartAutoFree 801a64f4
// smartFree 801a6598
void smartAutoFree(s32 type); // 801a64f4
void smartFree(SmartAllocation * allocation); // 801a6598
// smartAlloc 801a6794
// smartGarbage 801a6b60
// smartTexObj 801a6cf0

View File

@ -171,8 +171,9 @@ void smartInit() {
void * p = MEMAllocFromExpHeapEx(wp->heapHandle[SMART_HEAP_ID], size, 0x20);
assertf(p, "ƒ<EFBFBD>ƒƒŠŠm•ÛƒGƒ‰<EFBFBD>[ [id = %d][size = %d]", SMART_HEAP_ID, size);
swp->heapStart = p;
swp->unknown_0xe008 = 0;
swp->unknown_0xe00c = 0;
swp->firstAllocated = 0;
swp->lastAllocated = 0;
swp->heapSize = MEMGetSizeForMBlockExpHeap(swp->heapStart);
SmartAllocation * curAllocation = swp->allocations;
for (int i = 0; i < SMART_ALLOCATION_MAX; i++) {
@ -184,8 +185,33 @@ void smartInit() {
swp->firstFree->prev = NULL;
swp->lastFree = &swp->allocations[SMART_ALLOCATION_MAX - 1];
swp->lastFree->next = NULL;
swp->unknown_0xe018 = 0;
g_bFirstSmartAlloc = false;
}
void smartAutoFree(s32 type) {
SmartAllocation * curAllocation;
SmartAllocation * next; // only way register usage matched for next in 2nd loop
curAllocation = swp->firstAllocated;
while (curAllocation != NULL) {
next = curAllocation->next;
if (curAllocation->type == (type & 0xffff)) {
smartFree(curAllocation);
}
curAllocation = next;
}
if (type == 3) {
curAllocation = swp->firstAllocated;
while (curAllocation != NULL) {
next = curAllocation->next;
if (curAllocation->type == 4) {
smartFree(curAllocation);
}
curAllocation = next;
}
}
}
// a lot