diff --git a/minimal_heap.h b/minimal_heap.h index db74103..3d2dd0e 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -1,4 +1,4 @@ -/* Version 1.7 */ +/* Version 1.8 */ #ifndef __MINIMAL_HEAP_H__ #define __MINIMAL_HEAP_H__ @@ -169,8 +169,8 @@ void MIHP_ValidateHeapSegmentHeader(const MIHP_Heap* heap, const MIHP_HeapSegmen size_t MIHP_GetMinimalPayloadSize(const MIHP_Heap* heap); /* */ +#if MIHP_IMPLEMENTATION +#include "minimal_heap_implementation.inl" #endif -#if MIHP_IMPLEMENTATION - #include "minimal_heap_implementation.inl" #endif diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index 14897cc..ba5873f 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -8,7 +8,7 @@ MIHP_HeapConfig MIHP_MakeDefaultConfigPreset() MIHP_HeapConfig cfg = { 0 }; cfg.MinMemoryAreaSize = 4096 * 32; - cfg.MaxMemoryAreaSize = 4096 * 4096 * 8; + cfg.MaxMemoryAreaSize = 4096 * 4096 * 128; cfg.MinTotalTraversalsBeforeHeapExpansion = 10'000; cfg.MinHeapTraversalPercentToExpand = 80; @@ -187,10 +187,11 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size) /* No free segment found (in time), allocate new area */ - size_t newAreaSize = heap->Stats.TotalSize; + + size_t newAreaSize = heap->Stats.TotalSize / 4; // growth-rate of 1.25 while (newAreaSize < size) - newAreaSize = MIHP_MIN(heap->Config.MaxMemoryAreaSize, newAreaSize * 2); + newAreaSize = MIHP_MIN(heap->Config.MaxMemoryAreaSize, newAreaSize + newAreaSize / 4); MIHP_HeapMemoryAreaHeader* newArea = MIHP_CreateHeapMemoryArea(heap, newAreaSize); if (newArea == NULL) diff --git a/minimal_heap_test.c b/minimal_heap_test.c index 3537976..da65fb0 100644 --- a/minimal_heap_test.c +++ b/minimal_heap_test.c @@ -26,7 +26,7 @@ void OnHeapCorruptionDetectedCallback(const MIHP_Heap* heap, MIHP_HeapCorruption __debugbreak(); } -#define NUM_ALLOCATIONS (4096 * 4) +#define NUM_ALLOCATIONS (4096 * 4096) void* myptrs[NUM_ALLOCATIONS] = { 0 }; @@ -37,8 +37,9 @@ int main() config.PlatformRequestMemoryFn = RequestMemory; config.PlatformFreeMemoryFn = FreeMemory; config.OnHeapCorruptionDetectedFn = OnHeapCorruptionDetectedCallback; + config.MaxMemoryAreaSize *= 16; - config.HeapValidationMode = MIHP_HVM_Checksum; + config.HeapValidationMode = MIHP_HVM_MagicNumber; MIHP_Heap myHeap = { 0 }; MIHP_InitializeHeap(&myHeap, config);