tweaked heuristics

This commit is contained in:
2026-06-09 20:10:45 +02:00
parent 2150fcb0a2
commit 36159288d5
2 changed files with 9 additions and 9 deletions

View File

@@ -25,8 +25,8 @@
#define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000 #define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000
#endif #endif
#ifndef MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT #ifndef MIHP_MIN_EXPANSION_TRAVERSEL_RATIO_INT_PERCENT
#define MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50 #define MIHP_MIN_EXPANSION_TRAVERSEL_RATIO_INT_PERCENT 40
#endif #endif
#ifndef MIHP_ASSERT #ifndef MIHP_ASSERT

View File

@@ -81,9 +81,6 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
MIHP_LOCK_HEAP(&heap->HeapLock); MIHP_LOCK_HEAP(&heap->HeapLock);
size_t numTraversedSegments = 0;
bool triedLastAllocationArea = false;
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea; MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
do do
{ {
@@ -98,14 +95,17 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
if (currentArea->NumOccupiedSegments == currentArea->NumSegments) if (currentArea->NumOccupiedSegments == currentArea->NumSegments)
continue; continue;
size_t numTraversalsPerArea = MIHP_MAX(100, MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION * currentArea->NumSegments) / heap->Stats.NumTotalSegments;
size_t numTraversedAreaSegments = 0;
MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment; MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment;
while (nextSegment) while (nextSegment)
{ {
if (numTraversedSegments > MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION) if (numTraversedAreaSegments > numTraversalsPerArea)
if (numTraversedSegments * 100 > heap->Stats.NumTotalOccupiedSegments * MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT) if (numTraversedAreaSegments * 100 > currentArea->NumSegments * MIHP_MIN_EXPANSION_TRAVERSEL_RATIO_INT_PERCENT)
goto AllocateNewArea; break;
numTraversedSegments++; numTraversedAreaSegments++;
MIHP_HeapSegmentHeader* currentSegment = nextSegment; MIHP_HeapSegmentHeader* currentSegment = nextSegment;
MIHP_ValidateHeapSegmentHeader(heap, currentSegment); MIHP_ValidateHeapSegmentHeader(heap, currentSegment);