memory allocators

This commit is contained in:
2023-06-05 13:57:05 +06:00
parent 490d450a82
commit a983df1ac6
11 changed files with 328 additions and 8 deletions

47
tests/test_allocators.c Normal file
View File

@@ -0,0 +1,47 @@
#include "tests.h"
void _test_allocator(allocator_t* al){
void* ptr=allocator_alloc(al, 1);
allocator_free(al, ptr);
ptr=allocator_alloc(al, 5);
allocator_free(al, ptr);
ptr=allocator_alloc(al, 41);
allocator_free(al, ptr);
ptr=allocator_alloc(al, 19);
void* ptr1=allocator_alloc(al, 1);
void* ptr2=allocator_alloc(al, 5);
// allocator_free(al, ptr); // temp case
allocator_free(al, ptr2);
allocator_free(al, ptr1);
allocator_free(al, ptr);
ptr=allocator_alloc(al, 500);
ptr1=allocator_alloc(al, 1025);
allocator_free(al, ptr1);
allocator_free(al, ptr);/*
ptr=allocator_alloc(al, 5000);
ptr1=allocator_alloc(al, 5000000);
allocator_free(al, ptr1);
allocator_free(al, ptr);*/
}
void test_allocators(){
kprintf("\e[96m----------[test_allocators]-----------\n");
optime("test CstdAllocator", 10000,
CstdAllocator al;
CstdAllocator_construct(&al);
_test_allocator((allocator_t*)&al);
);
optime("test LinearAllocator", 10000,
LinearAllocator al;
LinearAllocator_construct(&al, 4096);
_test_allocator((allocator_t*)&al);
LinearAllocator_destruct(&al);
);
optime("test StackingAllocator", 10000,
StackingAllocator al;
StackingAllocator_construct(&al, 4096);
_test_allocator((allocator_t*)&al);
StackingAllocator_destruct(&al);
);
}

View File

@@ -6,6 +6,7 @@
extern "C" {
#endif
void test_allocators();
void test_cptr();
void test_string();
void test_safethrow();
@@ -20,22 +21,23 @@ void test_kprint_colors();
void test_kprint();
void test_type_system();
inline void test_all(){
static inline void test_all(){
kprintf("\e[97mkerep tests are starting!\n");
optime(__func__, 1,
test_cptr();
test_type_system();
test_allocators();
/*test_cptr();
test_string();
test_safethrow();
test_searchtree();
test_autoarr();
test_hash_functions();
test_hashtable();
test_dtsod();
test_autoarrVsVector();
test_rng_algorithms();
test_kprint_colors();
test_kprint();
test_hash_functions();
test_hashtable();
test_dtsod();
test_type_system();*/
kprintf("\e[96m--------------------------------------\e[0m\n");
);
}