Skip to content

Commit c0f1045

Browse files
committed
Simplify allocator and raw block navigation
1 parent bcb86fe commit c0f1045

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

Core/GameEngine/Include/Common/GameMemory.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class DynamicMemoryAllocator
490490
#endif // MEMORYPOOL_DEBUG
491491
#ifdef RTS_ENABLE_CRASHDUMP
492492
MemoryPoolSingleBlock* getFirstRawBlock() const;
493-
MemoryPoolSingleBlock* getNextRawBlock(MemoryPoolSingleBlock* block) const;
493+
MemoryPoolSingleBlock* getNextRawBlock(const MemoryPoolSingleBlock* block) const;
494494
void fillAllocationRangeForRawBlock(const MemoryPoolSingleBlock*, MemoryPoolAllocatedRange& allocationRange) const;
495495
#endif
496496
};
@@ -517,10 +517,7 @@ class AllocationRangeIterator
517517
reference operator*() { return m_range; }
518518
pointer operator->() { return &m_range; }
519519

520-
// Prefix increment
521520
AllocationRangeIterator& operator++();
522-
523-
// Postfix increment
524521
AllocationRangeIterator operator++(int);
525522

526523
friend const bool operator== (const AllocationRangeIterator& a, const AllocationRangeIterator& b);

Core/GameEngine/Include/Common/MiniDumper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ class MiniDumper
6363
void Initialize(const AsciiString& userDirPath);
6464
void ShutDown();
6565
void CreateMiniDump(DumpType dumpType);
66-
void DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize);
6766
void CleanupResources();
6867
Bool IsDumpThreadStillRunning() const;
6968
void ShutdownDumpThread();
7069
Bool ShouldWriteDataSegsForModule(const PWCHAR module) const;
70+
#ifndef DISABLE_GAMEMEMORY
71+
void MoveToNextAllocatorWithRawBlocks();
72+
void MoveToNextSingleBlock();
73+
void DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize);
74+
#endif
7175

7276
// Callbacks from dbghelp
7377
static BOOL CALLBACK MiniDumpCallback(PVOID CallbackParam, PMINIDUMP_CALLBACK_INPUT CallbackInput, PMINIDUMP_CALLBACK_OUTPUT CallbackOutput);

Core/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class MemoryPoolSingleBlock
441441

442442
MemoryPoolSingleBlock *getNextFreeBlock();
443443
void setNextFreeBlock(MemoryPoolSingleBlock *b);
444-
MemoryPoolSingleBlock *getNextRawBlock();
444+
MemoryPoolSingleBlock *getNextRawBlock() const;
445445
void setNextRawBlock(MemoryPoolSingleBlock *b);
446446

447447
#if defined(MEMORYPOOL_DEBUG) || defined(RTS_ENABLE_CRASHDUMP)
@@ -611,7 +611,7 @@ inline void MemoryPoolSingleBlock::setNextFreeBlock(MemoryPoolSingleBlock *b)
611611
return the next raw block in this dma. this call assumes that the block
612612
in question does NOT belong to a blob, and will assert if not.
613613
*/
614-
inline MemoryPoolSingleBlock *MemoryPoolSingleBlock::getNextRawBlock()
614+
inline MemoryPoolSingleBlock *MemoryPoolSingleBlock::getNextRawBlock() const
615615
{
616616
DEBUG_ASSERTCRASH(m_owningBlob == NULL, ("must be called on raw block"));
617617
return m_nextBlock;
@@ -2596,7 +2596,7 @@ MemoryPoolSingleBlock* DynamicMemoryAllocator::getFirstRawBlock() const
25962596
return m_rawBlocks;
25972597
}
25982598

2599-
MemoryPoolSingleBlock* DynamicMemoryAllocator::getNextRawBlock(MemoryPoolSingleBlock* block) const
2599+
MemoryPoolSingleBlock* DynamicMemoryAllocator::getNextRawBlock(const MemoryPoolSingleBlock* block) const
26002600
{
26012601
return block->getNextRawBlock();
26022602
}
@@ -3359,11 +3359,19 @@ void AllocationRangeIterator::moveToNextBlob()
33593359
}
33603360
}
33613361

3362-
// Prefix increment
3363-
AllocationRangeIterator& AllocationRangeIterator::operator++() { moveToNextBlob(); updateRange(); return *this; }
3362+
AllocationRangeIterator& AllocationRangeIterator::operator++()
3363+
{
3364+
moveToNextBlob();
3365+
updateRange();
3366+
return *this;
3367+
}
33643368

3365-
// Postfix increment
3366-
AllocationRangeIterator AllocationRangeIterator::operator++(int) { AllocationRangeIterator tmp = *this; ++(*this); return tmp; }
3369+
AllocationRangeIterator AllocationRangeIterator::operator++(int)
3370+
{
3371+
AllocationRangeIterator tmp = *this;
3372+
++(*this);
3373+
return tmp;
3374+
}
33673375

33683376
const bool operator== (const AllocationRangeIterator& a, const AllocationRangeIterator& b)
33693377
{

Core/GameEngine/Source/Common/System/MiniDumper.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,32 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
516516
}
517517

518518
#ifndef DISABLE_GAMEMEMORY
519+
void MiniDumper::MoveToNextAllocatorWithRawBlocks()
520+
{
521+
// Skip over DMAs that have no raw blocks
522+
while (m_currentAllocator && !m_currentAllocator->getFirstRawBlock())
523+
{
524+
m_currentAllocator = m_currentAllocator->getNextDmaInList();
525+
}
526+
527+
if (m_currentAllocator)
528+
{
529+
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
530+
}
531+
}
532+
533+
void MiniDumper::MoveToNextSingleBlock()
534+
{
535+
DEBUG_ASSERTCRASH(m_currentAllocator != NULL, ("MiniDumper::MoveToNextSingleBlock: m_currentAllocator is NULL"));
536+
m_currentSingleBlock = m_currentAllocator->getNextRawBlock(m_currentSingleBlock);
537+
538+
if (m_currentSingleBlock == NULL)
539+
{
540+
m_currentAllocator = m_currentAllocator->getNextDmaInList();
541+
MoveToNextAllocatorWithRawBlocks();
542+
}
543+
}
544+
519545
void MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
520546
{
521547
memorySize = 0;
@@ -531,8 +557,7 @@ void MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
531557
m_currentPool = TheMemoryPoolFactory->getFirstMemoryPool();
532558
m_rangeIter = TheMemoryPoolFactory->cbegin();
533559
m_currentAllocator = TheDynamicMemoryAllocator;
534-
if (m_currentAllocator)
535-
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
560+
MoveToNextAllocatorWithRawBlocks();
536561
}
537562
break;
538563
case DumpObjectsState_MemoryPools:
@@ -569,7 +594,7 @@ void MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
569594
{
570595
// Iterate through all the direct allocations ("raw blocks") done by DMAs, as these are done outside of the
571596
// memory pool factory allocations dumped in the previous phase.
572-
if (m_currentAllocator == NULL || m_currentSingleBlock == NULL)
597+
if (m_currentAllocator == NULL)
573598
{
574599
m_dumpObjectsState = DumpObjectsState_Completed;
575600
break;
@@ -579,14 +604,7 @@ void MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
579604
m_currentAllocator->fillAllocationRangeForRawBlock(m_currentSingleBlock, rawBlockRange);
580605
memoryBase = reinterpret_cast<ULONG64>(rawBlockRange.allocationAddr);
581606
memorySize = rawBlockRange.allocationSize;
582-
m_currentSingleBlock = m_currentAllocator->getNextRawBlock(m_currentSingleBlock);
583-
584-
if (m_currentSingleBlock == NULL)
585-
{
586-
m_currentAllocator = m_currentAllocator->getNextDmaInList();
587-
if (m_currentAllocator)
588-
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
589-
}
607+
MoveToNextSingleBlock();
590608
break;
591609
}
592610
case DumpObjectsState_Completed:

0 commit comments

Comments
 (0)