From 3582e21a8494744c5ef6aace29899d6b643cd1ed Mon Sep 17 00:00:00 2001 From: ToyB-Chan Date: Tue, 9 Jun 2026 19:25:07 +0200 Subject: [PATCH] tweaked heuristics --- minimal_heap.h | 9 +++++++++ minimal_heap_implementation.inl | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/minimal_heap.h b/minimal_heap.h index 3d0c32b..ad1c652 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -16,10 +16,19 @@ #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM 2 /* Defines to be configured by the library user */ + #ifndef MIHP_HEAP_STRUCTURE_VALIDATION_TYPE #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM #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 #define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } #endif diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index dc761bd..4200a2c 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -108,8 +108,9 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size) MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment; while (nextSegment) { - if (numTraversedSegments * 100 > heap->Stats.NumTotalSegments * 80) - goto AllocateNewArea; + if (numTraversedSegments > MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION) + if (numTraversedSegments * 100 > heap->Stats.NumTotalOccupiedSegments * MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT) + goto AllocateNewArea; numTraversedSegments++;