added first heuristic

This commit is contained in:
2026-06-09 03:30:38 +02:00
parent 1501e2e65d
commit eaddbd31fd
2 changed files with 10 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
/* Version 1.3b */
/* Version 1.3c */
#ifndef __MINIMAL_HEAP_H__
#define __MINIMAL_HEAP_H__

View File

@@ -81,6 +81,8 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
MIHP_LOCK_HEAP(&heap->HeapLock);
size_t numTraversedSegments = 0;
bool triedLastAllocationArea = false;
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
while (nextArea)
@@ -106,6 +108,11 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
MIHP_HeapSegmentHeader* nextSegment = currentArea->FirstSegment;
while (nextSegment)
{
if (numTraversedSegments * 100 > heap->Stats.NumTotalSegments * 50)
goto AllocateNewArea;
numTraversedSegments++;
MIHP_HeapSegmentHeader* currentSegment = nextSegment;
MIHP_ValidateHeapSegmentHeader(heap, currentSegment);
nextSegment = nextSegment->NextSegment;
@@ -141,6 +148,8 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
}
}
AllocateNewArea:
size_t newAreaSize = heap->Stats.TotalSize;
while (newAreaSize < size)