tweaked heuristics

This commit is contained in:
2026-06-09 19:25:07 +02:00
parent b6bc80cf22
commit 3582e21a84
2 changed files with 12 additions and 2 deletions

View File

@@ -16,10 +16,19 @@
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM 2 #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM 2
/* Defines to be configured by the library user */ /* Defines to be configured by the library user */
#ifndef MIHP_HEAP_STRUCTURE_VALIDATION_TYPE #ifndef MIHP_HEAP_STRUCTURE_VALIDATION_TYPE
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM
#endif #endif
#ifndef MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION
#define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000
#endif
#ifndef MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT
#define MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50
#endif
#ifndef MIHP_ASSERT #ifndef MIHP_ASSERT
#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } #define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; }
#endif #endif

View File

@@ -108,8 +108,9 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment; MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment;
while (nextSegment) while (nextSegment)
{ {
if (numTraversedSegments * 100 > heap->Stats.NumTotalSegments * 80) if (numTraversedSegments > MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION)
goto AllocateNewArea; if (numTraversedSegments * 100 > heap->Stats.NumTotalOccupiedSegments * MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT)
goto AllocateNewArea;
numTraversedSegments++; numTraversedSegments++;