@@ -23,7 +23,8 @@ static inline U1 T_round_up(U2 val, int align) {
2323}
2424
2525CGameAllocator::SGameMemInfo* CGameAllocator::GetMemInfoFromBlockPtr (const void * ptr) const {
26- return (SGameMemInfo*)((uchar*)(ptr) - sizeof (SGameMemInfo));
26+ return reinterpret_cast < SGameMemInfo* >(reinterpret_cast < uintptr_t >(ptr) -
27+ sizeof (SGameMemInfo));
2728}
2829
2930CGameAllocator::CGameAllocator ()
@@ -68,9 +69,9 @@ CGameAllocator::~CGameAllocator() {
6869bool CGameAllocator::Initialize (COsContext& ctx) {
6970 x8_heapSize = ctx.GetBaseFreeRam () - 2 * sizeof (SGameMemInfo);
7071 xc_first = static_cast < SGameMemInfo* >(OSAllocFromArenaLo (x8_heapSize, sizeof (SGameMemInfo)));
71- xb4_physicalAddr =
72- reinterpret_cast < void * >( reinterpret_cast < intptr_t >(xc_first) -
73- (reinterpret_cast < uintptr_t >(xc_first) & 0xf0000000 ));
72+ xb4_physicalAddr = reinterpret_cast < void * >(
73+ reinterpret_cast < intptr_t >(xc_first) -
74+ (reinterpret_cast < uintptr_t >(xc_first) & kAllocatorPointerTopNybbleMask ));
7475 OSGetArenaLo ();
7576 x10_last =
7677 reinterpret_cast < SGameMemInfo* >(reinterpret_cast < char * >(xc_first - 1 ) + x8_heapSize);
@@ -394,7 +395,7 @@ bool CGameAllocator::FreeNormalAllocation(const void* ptr) {
394395 SGameMemInfo* k = info->GetNext ();
395396 size_t len = 0 ;
396397 if (k) {
397- len = ( size_t )k - ( size_t ) info - sizeof (SGameMemInfo);
398+ len = reinterpret_cast < size_t >(k) - reinterpret_cast < size_t >( info) - sizeof (SGameMemInfo);
398399 }
399400 info->SetLength (len);
400401
@@ -472,10 +473,10 @@ void CGameAllocator::SetOutOfMemoryCallback(FOutOfMemoryCb cb, const void* targe
472473};
473474
474475IAllocator::SAllocInfo CGameAllocator::GetAllocInfo (const void * ptr) const {
475- SGameMemInfo* info = GetMemInfoFromBlockPtr (ptr);
476+ const SGameMemInfo* info = GetMemInfoFromBlockPtr (ptr);
476477
477- return SAllocInfo (( const void *) info, info->GetLength (), info->IsAllocated (), false ,
478- info->x8_fileAndLine , info-> xc_type );
478+ return SAllocInfo (info, info->GetLength (), info->IsAllocated (), false , info-> x8_fileAndLine ,
479+ info->xc_type );
479480};
480481
481482IAllocator::SMetrics CGameAllocator::GetMetrics () const {
@@ -487,22 +488,22 @@ IAllocator::SMetrics CGameAllocator::GetMetrics() const {
487488 x74_mediumPool != nullptr
488489 ? x74_mediumPool->GetTotalEntries () - x74_mediumPool->GetNumBlocksAvailable ()
489490 : 0 ;
490- uint mediumAllocNumAllocs = x74_mediumPool != nullptr ? x74_mediumPool->GetNumAllocs () : 0 ;
491+ const uint mediumAllocNumAllocs = x74_mediumPool != nullptr ? x74_mediumPool->GetNumAllocs () : 0 ;
491492 SMetrics ret (x8_heapSize, x80_, x84_, x88_, x8c_, x90_heapSize2, x94_, x98_, x9c_, xa0_, xa4_,
492493 x60_smallAllocPool != nullptr ? x60_smallAllocPool->GetNumAllocs () : 0 ,
493494 x60_smallAllocPool != nullptr ? x60_smallAllocPool->GetAllocatedSize () : 0 ,
494495 x60_smallAllocPool != nullptr ? x60_smallAllocPool->GetNumBlocksAvailable () : 0 ,
495496 mediumAllocNumAllocs, mediumAllocAllocatedSize, mediumAllocBlocksAvailable,
496- x80_ - xb0_, ( uintptr_t ) xb4_physicalAddr, xbc_, mediumAllocTotalAllocated ,
497- xb8_fakeStatics);
497+ x80_ - xb0_, reinterpret_cast < uintptr_t >( xb4_physicalAddr) , xbc_,
498+ mediumAllocTotalAllocated, xb8_fakeStatics);
498499 xb0_ = x80_;
499500 return ret;
500501};
501502
502503int CGameAllocator::EnumAllocations (FEnumAllocationsCb func, const void * ptr, bool b) const {
503504
504505 int i = 0 ;
505- SGameMemInfo* iter = xc_first;
506+ const SGameMemInfo* iter = xc_first;
506507
507508 while (iter != nullptr ) {
508509 if (!iter->IsPostGuardIntact ()) {
@@ -513,9 +514,9 @@ int CGameAllocator::EnumAllocations(FEnumAllocationsCb func, const void* ptr, bo
513514 return -1 ;
514515 }
515516
516- SGameMemInfo* next = iter->GetNext ();
517- SAllocInfo alloc (( const void *) iter, iter->GetLength (), iter->IsAllocated (), false ,
518- iter->x8_fileAndLine , iter-> xc_type );
517+ const SGameMemInfo* next = iter->GetNext ();
518+ SAllocInfo alloc (iter, iter->GetLength (), iter->IsAllocated (), false , iter-> x8_fileAndLine ,
519+ iter->xc_type );
519520 func (alloc, ptr);
520521 ++i;
521522 iter = next;
@@ -524,7 +525,7 @@ int CGameAllocator::EnumAllocations(FEnumAllocationsCb func, const void* ptr, bo
524525 return i;
525526};
526527
527- uint CGameAllocator::GetFreeBinEntryForSize (uint size) {
528+ uint CGameAllocator::GetFreeBinEntryForSize (const uint size) {
528529 uint maxLen = 0x20 ;
529530 uint bin = 0 ;
530531
@@ -584,7 +585,7 @@ void CGameAllocator::DumpAllocations() const {
584585}
585586
586587size_t CGameAllocator::GetLargestFreeChunk () const {
587- SGameMemInfo* iter = xc_first;
588+ const SGameMemInfo* iter = xc_first;
588589 size_t ret = 0 ;
589590 while (iter != nullptr ) {
590591 if (!iter->IsAllocated () && iter->GetLength () > ret) {
@@ -595,4 +596,4 @@ size_t CGameAllocator::GetLargestFreeChunk() const {
595596
596597 return ret;
597598}
598- void CGameAllocator::OffsetFakeStatics (int offset) { xb8_fakeStatics += offset; }
599+ void CGameAllocator::OffsetFakeStatics (const int offset) { xb8_fakeStatics += offset; }
0 commit comments