4coder/custom/4coder_malloc_allocator.cpp

58 lines
1.1 KiB
C++
Raw Normal View History

2019-06-01 23:58:28 +00:00
/*
* 4coder malloc base allocator
*/
// TOP
#include <stdlib.h>
2019-12-22 21:43:36 +00:00
#if !OS_MAC
# include <malloc.h>
#endif
2019-06-01 23:58:28 +00:00
internal void*
base_reserve__malloc(void *user_data, u64 size, u64 *size_out, String_Const_u8 location){
2019-06-01 23:58:28 +00:00
*size_out = size;
return(malloc((size_t)size));
2019-06-01 23:58:28 +00:00
}
internal void
base_free__malloc(void *user_data, void *ptr){
free(ptr);
}
internal Base_Allocator
make_malloc_base_allocator(void){
return(make_base_allocator(base_reserve__malloc, 0, 0,
base_free__malloc, 0, 0));
}
global Base_Allocator malloc_base_allocator = {};
2019-09-04 18:26:51 +00:00
internal Base_Allocator*
get_allocator_malloc(void){
2019-06-01 23:58:28 +00:00
if (malloc_base_allocator.reserve == 0){
malloc_base_allocator = make_malloc_base_allocator();
}
2019-09-04 18:26:51 +00:00
return(&malloc_base_allocator);
}
internal Arena
make_arena_malloc(u64 chunk_size, u64 align){
2019-09-04 18:26:51 +00:00
Base_Allocator *allocator = get_allocator_malloc();
return(make_arena(allocator, chunk_size, align));
2019-06-01 23:58:28 +00:00
}
internal Arena
make_arena_malloc(u64 chunk_size){
2019-06-01 23:58:28 +00:00
return(make_arena_malloc(chunk_size, 8));
}
internal Arena
make_arena_malloc(void){
return(make_arena_malloc(KB(16), 8));
}
// BOTTOM