mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
more tests
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define USE_MALLOC 0
|
||||
|
||||
void* MIHP_PlatformRequestMemory(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
@@ -19,56 +21,81 @@ void MIHP_PlatformOnHeapCorruptionDetected(MIHP_HeapCorruptionInfo info)
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
#define NUM_ALLOCATIONS (4096 * 1)
|
||||
#define NUM_ALLOCATIONS (4096 * 512)
|
||||
|
||||
void* myptrs[NUM_ALLOCATIONS] = { 0 };
|
||||
|
||||
int main()
|
||||
{
|
||||
MIHP_HeapConfig config = {0};
|
||||
config.AllocationAlignment = 128;
|
||||
config.AllocationInitialValue = 0xbe;
|
||||
config.AllocationAlignment = 16;
|
||||
config.MinimalMemoryAreaSize = 4096 * 32;
|
||||
config.MaximalMemoryAreaSize = 4096 * 4096;
|
||||
config.MaximalMemoryAreaSize = 4096ull * 4096ull * 4096ull;
|
||||
MIHP_HeapInfo* myHeap = MIHP_CreateHeap(config);
|
||||
|
||||
for (int i = 0; i < NUM_ALLOCATIONS; i++)
|
||||
{
|
||||
clock_t start = clock();
|
||||
|
||||
for (int i = 0; i < NUM_ALLOCATIONS; i++)
|
||||
{
|
||||
size_t size = 473 + (i % 5 == 0 ? 854 : 0);
|
||||
//myptrs[i] = malloc(size);
|
||||
myptrs[i] = MIHP_Allocate(myHeap, size);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
}
|
||||
|
||||
clock_t end = clock();
|
||||
printf("Allocating took %f seconds\n", ((double)(end - start)) / CLOCKS_PER_SEC);
|
||||
size_t size = 473 + (i % 5 == 0 ? 854 : 0);
|
||||
#if USE_MALLOC
|
||||
myptrs[i] = malloc(size);
|
||||
#else
|
||||
myptrs[i] = MIHP_Allocate(myHeap, size);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
__debugbreak();
|
||||
|
||||
for (int i = 0; i < NUM_ALLOCATIONS; i++)
|
||||
{
|
||||
clock_t start = clock();
|
||||
|
||||
for (int z = 15; z >= 0; z--)
|
||||
if (rand() % 3 == 0)
|
||||
{
|
||||
for (int y = 0; y < NUM_ALLOCATIONS / 16; y++)
|
||||
{
|
||||
int i = z + y * 16;
|
||||
#if USE_MALLOC
|
||||
free(myptrs[i]);
|
||||
#else
|
||||
MIHP_Free(myHeap, myptrs[i]);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
#endif
|
||||
|
||||
//free(myptrs[i]);
|
||||
MIHP_Free(myHeap, myptrs[i]);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
myptrs[i] = NULL;
|
||||
}
|
||||
myptrs[i] = NULL;
|
||||
}
|
||||
|
||||
clock_t end = clock();
|
||||
printf("Freeing took %f seconds\n", ((double)(end - start)) / CLOCKS_PER_SEC);
|
||||
}
|
||||
|
||||
__debugbreak();
|
||||
|
||||
for (int i = 0; i < NUM_ALLOCATIONS; i++)
|
||||
{
|
||||
volatile int n = i;
|
||||
if (!myptrs[i])
|
||||
{
|
||||
size_t size = 541 + rand() % 2564;
|
||||
|
||||
#if USE_MALLOC
|
||||
myptrs[i] = malloc(size);
|
||||
#else
|
||||
myptrs[i] = MIHP_Allocate(myHeap, size);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__debugbreak();
|
||||
|
||||
for (int z = 15; z >= 0; z--)
|
||||
for (int y = 0; y < NUM_ALLOCATIONS / 16; y++)
|
||||
{
|
||||
int i = z + y * 16;
|
||||
#if USE_MALLOC
|
||||
free(myptrs[i]);
|
||||
#else
|
||||
MIHP_Free(myHeap, myptrs[i]);
|
||||
MIHP_ValidateHeap(myHeap);
|
||||
#endif
|
||||
|
||||
myptrs[i] = NULL;
|
||||
}
|
||||
|
||||
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user