mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
tweaked growth rate
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* Version 1.7 */
|
/* Version 1.8 */
|
||||||
|
|
||||||
#ifndef __MINIMAL_HEAP_H__
|
#ifndef __MINIMAL_HEAP_H__
|
||||||
#define __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);
|
size_t MIHP_GetMinimalPayloadSize(const MIHP_Heap* heap);
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
|
#if MIHP_IMPLEMENTATION
|
||||||
|
#include "minimal_heap_implementation.inl"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MIHP_IMPLEMENTATION
|
|
||||||
#include "minimal_heap_implementation.inl"
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ MIHP_HeapConfig MIHP_MakeDefaultConfigPreset()
|
|||||||
MIHP_HeapConfig cfg = { 0 };
|
MIHP_HeapConfig cfg = { 0 };
|
||||||
|
|
||||||
cfg.MinMemoryAreaSize = 4096 * 32;
|
cfg.MinMemoryAreaSize = 4096 * 32;
|
||||||
cfg.MaxMemoryAreaSize = 4096 * 4096 * 8;
|
cfg.MaxMemoryAreaSize = 4096 * 4096 * 128;
|
||||||
|
|
||||||
cfg.MinTotalTraversalsBeforeHeapExpansion = 10'000;
|
cfg.MinTotalTraversalsBeforeHeapExpansion = 10'000;
|
||||||
cfg.MinHeapTraversalPercentToExpand = 80;
|
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 */
|
/* 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)
|
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);
|
MIHP_HeapMemoryAreaHeader* newArea = MIHP_CreateHeapMemoryArea(heap, newAreaSize);
|
||||||
if (newArea == NULL)
|
if (newArea == NULL)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void OnHeapCorruptionDetectedCallback(const MIHP_Heap* heap, MIHP_HeapCorruption
|
|||||||
__debugbreak();
|
__debugbreak();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUM_ALLOCATIONS (4096 * 4)
|
#define NUM_ALLOCATIONS (4096 * 4096)
|
||||||
|
|
||||||
void* myptrs[NUM_ALLOCATIONS] = { 0 };
|
void* myptrs[NUM_ALLOCATIONS] = { 0 };
|
||||||
|
|
||||||
@@ -37,8 +37,9 @@ int main()
|
|||||||
config.PlatformRequestMemoryFn = RequestMemory;
|
config.PlatformRequestMemoryFn = RequestMemory;
|
||||||
config.PlatformFreeMemoryFn = FreeMemory;
|
config.PlatformFreeMemoryFn = FreeMemory;
|
||||||
config.OnHeapCorruptionDetectedFn = OnHeapCorruptionDetectedCallback;
|
config.OnHeapCorruptionDetectedFn = OnHeapCorruptionDetectedCallback;
|
||||||
|
config.MaxMemoryAreaSize *= 16;
|
||||||
|
|
||||||
config.HeapValidationMode = MIHP_HVM_Checksum;
|
config.HeapValidationMode = MIHP_HVM_MagicNumber;
|
||||||
|
|
||||||
MIHP_Heap myHeap = { 0 };
|
MIHP_Heap myHeap = { 0 };
|
||||||
MIHP_InitializeHeap(&myHeap, config);
|
MIHP_InitializeHeap(&myHeap, config);
|
||||||
|
|||||||
Reference in New Issue
Block a user