More CMediumAllocPool matches

This commit is contained in:
Phillip Stephens 2023-10-03 23:56:48 -07:00
parent 8d531cf609
commit 07962b0ff0
3 changed files with 45 additions and 22 deletions

View File

@ -9,15 +9,15 @@ struct SMediumAllocPuddle {
~SMediumAllocPuddle();
void* FindFree(uint blockCount);
void* FindFreeEntry(uint blockCount);
bool Free(const void* ptr);
void Free(const void* ptr);
uint GetUnkx10() const { return x10_; }
uint GetNumBlocks() const { return x14_numBlocks; }
uint GetNumAllocs() const { return x18_numAllocs; }
uint GetNumEntries() const { return x1c_numEntries; }
bool GetUnk2() const { return x20_unk2; }
static uint GetBlockOffset(const void* ptrA, const void* ptrB);
const uint GetUnkx10() const { return x10_; }
const uint GetNumBlocks() const { return x14_numBlocks; }
const uint GetNumAllocs() const { return x18_numAllocs; }
const uint GetNumEntries() const { return x1c_numEntries; }
const bool GetUnk2() const { return x20_unk2; }
const uint GetPtrOffset(const void* ptr) const { return (uchar*)ptr - x0_mainData.get(); }
static ushort GetBlockOffset(const void* ptrA, const void* ptrB);
static void InitBookKeeping(uchar* bookKeepingPtr, const ushort blockCount);
private:
@ -38,7 +38,7 @@ public:
CMediumAllocPool();
void* Alloc(uint size);
bool HasPuddles() const;
void AddPuddle(uint, void*, bool);
void AddPuddle(const uint, void*, const bool);
void ClearPuddles();
int Free(const void* ptr);

View File

@ -12,7 +12,7 @@ class list {
public:
class iterator;
class const_iterator;
iterator erase(const iterator& item);
iterator erase(const iterator& item) { return do_erase(item.get_node()); }
private:
struct node;
@ -33,9 +33,7 @@ public:
size_t size() const { return x14_count; }
bool empty() const { return x14_count == 0; }
void pop_front() {
erase(x4_start);
}
void pop_front() { erase(x4_start); }
iterator begin() { return iterator(x4_start); }
const_iterator begin() const { return const_iterator(x4_start); }
@ -166,7 +164,6 @@ list< T, Alloc >::~list() {
}
}
template < typename T, typename Alloc >
typename list< T, Alloc >::node* list< T, Alloc >::do_erase(node* node) {
typename list< T, Alloc >::node* result = node->get_next();

View File

@ -43,7 +43,25 @@ void* CMediumAllocPool::Alloc(uint len) {
return ret;
}
int CMediumAllocPool::Free(const void* ptr) {}
int CMediumAllocPool::Free(const void* ptr) {
rstl::list<SMediumAllocPuddle>::node* node = x0_list.begin().get_node();
for (; node != x0_list.end().get_node(); node = node->get_next()) {
SMediumAllocPuddle* puddle = node->get_value();
if (puddle->GetPtrOffset(ptr) < puddle->GetNumEntries() * 32) {
puddle->Free(ptr);
if (node->get_value()->GetNumAllocs() == 0 && node->get_value()->GetUnk2()) {
if (x18_lastNodePrev == node ) {
x18_lastNodePrev = x0_list.begin().get_node();
}
x0_list.erase(node);
}
return 2;
}
}
return 1;
}
uint CMediumAllocPool::GetNumAllocs() {
uint ret = 0;
@ -72,7 +90,7 @@ uint CMediumAllocPool::GetNumBlocksAvailable() {
}
/* this is such a hack... */
#pragma inline_max_size(250)
#pragma inline_max_size(325)
void CMediumAllocPool::AddPuddle(uint len, void* data, const bool unk) {
x0_list.push_back(SMediumAllocPuddle(len, data, unk));
x18_lastNodePrev = x0_list.end().get_node();
@ -115,9 +133,17 @@ void* SMediumAllocPuddle::FindFree(uint blockCount) {
void* SMediumAllocPuddle::FindFreeEntry(uint numBlocks) { return nullptr; }
bool SMediumAllocPuddle::Free(const void* ptr) {}
void SMediumAllocPuddle::Free(const void* ptr) {}
uint SMediumAllocPuddle::GetBlockOffset(const void* ptrA, const void* ptrB) { return 0; }
ushort SMediumAllocPuddle::GetBlockOffset(const void* ptr1, const void* ptr2) {
unsigned char tmp = (uchar*)ptr2 - (uchar*)ptr1 > 1 ? ((uchar*)ptr1)[1] : 0;
ushort x = tmp + (*(uchar*)(ptr1) & 0x7f) * 0x100;
if ((x & 0x6000) == 0) {
return x;
}
return (x & 0x6000u) == 0x6000u ? 3 : (((x & 0x6000u) != 0x4000) ? 0 : 1) + 1;
}
void SMediumAllocPuddle::InitBookKeeping(uchar* bookKeepingPtr, ushort blockCount) {
if (blockCount < 4) {