This commit is contained in:
2026-06-08 08:07:09 +02:00
parent c134adc3b1
commit 5da9598053
2 changed files with 8 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ MIHP_HeapInfo* MIHP_CreateHeap(MIHP_HeapConfig config)
heap->Config = config; heap->Config = config;
heap->FirstArea = MIHP_CreateHeapMemoryArea(heap, config.MinimalMemoryAreaSize); heap->FirstArea = MIHP_CreateHeapMemoryArea(heap, config.MinimalMemoryAreaSize);
heap->LastAllocationArea = heap->FirstArea; heap->LastSuccessfulAllocationArea = heap->FirstArea;
if (heap->FirstArea == NULL) if (heap->FirstArea == NULL)
{ {
MIHP_PlatformFreeMemory(heap, sizeof(MIHP_HeapInfo)); MIHP_PlatformFreeMemory(heap, sizeof(MIHP_HeapInfo));
@@ -71,16 +71,16 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size)
MIHP_LOCK_HEAP(&heap->HeapLock); MIHP_LOCK_HEAP(&heap->HeapLock);
bool checkedLastAllocationArea = false; bool triedLastAllocationArea = false;
MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea; MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea;
while (nextArea) while (nextArea)
{ {
MIHP_HeapMemoryAreaHeader* currentArea = NULL; MIHP_HeapMemoryAreaHeader* currentArea = NULL;
if (!checkedLastAllocationArea) if (!triedLastAllocationArea)
{ {
currentArea = heap->LastAllocationArea; currentArea = heap->LastSuccessfulAllocationArea;
checkedLastAllocationArea = true; triedLastAllocationArea = true;
} }
else else
{ {
@@ -122,7 +122,7 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size)
heap->Stats.NumTotalOccupiedSegments++; heap->Stats.NumTotalOccupiedSegments++;
heap->Stats.TotalOccupiedSize += targetSegment->OccupiedSize; heap->Stats.TotalOccupiedSize += targetSegment->OccupiedSize;
heap->LastAllocationArea = currentArea; heap->LastSuccessfulAllocationArea = currentArea;
MIHP_UNLOCK_HEAP(&heap->HeapLock); MIHP_UNLOCK_HEAP(&heap->HeapLock);
@@ -147,6 +147,7 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size)
heap->FirstArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap->FirstArea); heap->FirstArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap->FirstArea);
heap->FirstArea = newArea; heap->FirstArea = newArea;
heap->LastSuccessfulAllocationArea = newArea;
newArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(newArea); newArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(newArea);
MIHP_UNLOCK_HEAP(&heap->HeapLock); MIHP_UNLOCK_HEAP(&heap->HeapLock);

View File

@@ -31,7 +31,7 @@ int main()
config.AllocationInitialValue = 0xbe; config.AllocationInitialValue = 0xbe;
config.AllocationAlignment = 16; config.AllocationAlignment = 16;
config.MinimalMemoryAreaSize = 4096 * 32; config.MinimalMemoryAreaSize = 4096 * 32;
config.MaximalMemoryAreaSize = 4096ull * 4096ull; config.MaximalMemoryAreaSize = 4096ull * 4096ull * 4096ull;
MIHP_HeapInfo* myHeap = MIHP_CreateHeap(config); MIHP_HeapInfo* myHeap = MIHP_CreateHeap(config);
for (int i = 0; i < NUM_ALLOCATIONS; i++) for (int i = 0; i < NUM_ALLOCATIONS; i++)