mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
changed the order areas are traversed
This commit is contained in:
@@ -25,8 +25,8 @@
|
|||||||
#define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000
|
#define MIHP_MIN_TRAVERSELS_BEFORE_EXPANSION 10000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT
|
#ifndef MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT
|
||||||
#define MIHP_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50
|
#define MIHP_MIN_EXPANSION_TRAVERSEL_OCCUPIED_INT_PERCENT 50
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MIHP_ASSERT
|
#ifndef MIHP_ASSERT
|
||||||
|
|||||||
@@ -85,20 +85,13 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
|
|||||||
|
|
||||||
bool triedLastAllocationArea = false;
|
bool triedLastAllocationArea = false;
|
||||||
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
|
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
|
||||||
while (nextArea)
|
do
|
||||||
{
|
{
|
||||||
MIHP_HeapMemoryAreaHeader* currentArea = NULL;
|
MIHP_HeapMemoryAreaHeader* currentArea = nextArea;
|
||||||
|
|
||||||
if (!triedLastAllocationArea)
|
|
||||||
{
|
|
||||||
currentArea = heap->LastSuccessfulAllocationArea;
|
|
||||||
triedLastAllocationArea = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
currentArea = nextArea;
|
|
||||||
nextArea = currentArea->NextArea;
|
nextArea = currentArea->NextArea;
|
||||||
}
|
|
||||||
|
if (nextArea == NULL)
|
||||||
|
nextArea = heap->FirstArea;
|
||||||
|
|
||||||
MIHP_ValidateHeapMemoryAreaHeader(heap, currentArea);
|
MIHP_ValidateHeapMemoryAreaHeader(heap, currentArea);
|
||||||
|
|
||||||
@@ -147,7 +140,7 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
} while (nextArea != heap->LastSuccessfulAllocationArea);
|
||||||
|
|
||||||
AllocateNewArea:
|
AllocateNewArea:
|
||||||
size_t newAreaSize = heap->Stats.TotalSize;
|
size_t newAreaSize = heap->Stats.TotalSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user