From 2150fcb0a204e37c25baf663e4927156bf74a8d4 Mon Sep 17 00:00:00 2001 From: ToyB-Chan Date: Tue, 9 Jun 2026 19:41:06 +0200 Subject: [PATCH] changed the order areas are traversed --- minimal_heap.h | 4 ++-- minimal_heap_implementation.inl | 19 ++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/minimal_heap.h b/minimal_heap.h index ad1c652..fcc1ea1 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -25,8 +25,8 @@ #define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000 #endif -#ifndef MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT - #define MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50 +#ifndef MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT + #define MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50 #endif #ifndef MIHP_ASSERT diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index 4200a2c..b108377 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -85,20 +85,13 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size) bool triedLastAllocationArea = false; MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea; - while (nextArea) + do { - MIHP_HeapMemoryAreaHeader* currentArea = NULL; + MIHP_HeapMemoryAreaHeader* currentArea = nextArea; + nextArea = currentArea->NextArea; - if (!triedLastAllocationArea) - { - currentArea = heap->LastSuccessfulAllocationArea; - triedLastAllocationArea = true; - } - else - { - currentArea = nextArea; - nextArea = currentArea->NextArea; - } + if (nextArea == NULL) + nextArea = heap->FirstArea; MIHP_ValidateHeapMemoryAreaHeader(heap, currentArea); @@ -147,7 +140,7 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size) return data; } - } + } while (nextArea != heap->LastSuccessfulAllocationArea); AllocateNewArea: size_t newAreaSize = heap->Stats.TotalSize;