mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
added first heuristic
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Version 1.3b */
|
||||
/* Version 1.3c */
|
||||
|
||||
#ifndef __MINIMAL_HEAP_H__
|
||||
#define __MINIMAL_HEAP_H__
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user