memory.hpp no longer uses memory mappings by default

This commit is contained in:
2024-11-30 17:18:49 -05:00
parent 5527a27f7b
commit 06deb1e836
9 changed files with 170 additions and 102 deletions

View File

@ -19,7 +19,7 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
{
if ( ( last->TotalUsed + size ) > last->TotalSize )
{
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
Arena bucket = arena_init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
@ -30,7 +30,7 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
last = & Global_AllocatorBuckets.back();
}
return alloc_align( * last, size, alignment );
return alloc_align( allocator_info(* last), size, alignment );
}
case EAllocation_FREE:
{
@ -46,7 +46,7 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
{
if ( last->TotalUsed + size > last->TotalSize )
{
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
Arena bucket = arena_init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
@ -240,7 +240,7 @@ void init()
if ( Global_AllocatorBuckets == nullptr )
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
Arena bucket = arena_init_from_allocator( heap(), Global_BucketSize );
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create first bucket for Global_AllocatorBuckets");
@ -264,16 +264,16 @@ void init()
// Setup the code pool and code entries arena.
{
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
Pool code_pool = pool_init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
CodePools.append( code_pool );
LexArena = Arena::init_from_allocator( Allocator_Lexer, LexAllocator_Size );
LexArena = arena_init_from_allocator( Allocator_Lexer, LexAllocator_Size );
Arena string_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
Arena string_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( string_arena.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the string arena" );
@ -303,7 +303,7 @@ void deinit()
do
{
Pool* code_pool = & CodePools[index];
code_pool->free();
free(* code_pool);
index++;
}
while ( left--, left );
@ -313,7 +313,7 @@ void deinit()
do
{
Arena* string_arena = & StringArenas[index];
string_arena->free();
free(* string_arena);
index++;
}
while ( left--, left );
@ -323,7 +323,7 @@ void deinit()
CodePools.free();
StringArenas.free();
LexArena.free();
free(LexArena);
PreprocessorDefines.free();
@ -332,7 +332,7 @@ void deinit()
do
{
Arena* bucket = & Global_AllocatorBuckets[ index ];
bucket->free();
free(* bucket);
index++;
}
while ( left--, left );
@ -348,7 +348,7 @@ void reset()
do
{
Pool* code_pool = & CodePools[index];
code_pool->clear();
clear(* code_pool);
index++;
}
while ( left--, left );
@ -376,7 +376,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
if ( last->TotalUsed + ssize(size_req) > last->TotalSize )
{
Arena new_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
Arena new_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( ! StringArenas.append( new_arena ) )
GEN_FATAL( "gen::get_string_allocator: Failed to allocate a new string arena" );
@ -384,7 +384,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
last = & StringArenas.back();
}
return * last;
return allocator_info(* last);
}
// Will either make or retrive a code string.
@ -411,7 +411,7 @@ Code make_code()
Pool* allocator = & CodePools.back();
if ( allocator->FreeList == nullptr )
{
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
Pool code_pool = pool_init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
@ -422,7 +422,7 @@ Code make_code()
allocator = & CodePools.back();
}
Code result { rcast( AST*, alloc( * allocator, sizeof(AST) )) };
Code result { rcast( AST*, alloc( allocator_info(* allocator), sizeof(AST) )) };
mem_set( result.ast, 0, sizeof(AST) );
// result->Type = ECode::Invalid;

View File

@ -16,8 +16,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
local_persist
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
tok_map_arena = init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
tok_map = HashTable<StrC>::init( tok_map_arena );
tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
tok_map = HashTable<StrC>::init( allocator_info(tok_map_arena) );
s32 left = num_tokens - 1;
@ -95,7 +95,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
}
tok_map.clear();
tok_map_arena.free();
free(tok_map_arena);
ssize result = buf_size - remaining;

View File

@ -132,12 +132,12 @@ bool TokArray::__eat( TokType type )
internal
void init()
{
Tokens = Array<Token>::init_reserve( LexArena
Tokens = array_init_reserve<Token>( allocator_info(LexArena)
, ( LexAllocator_Size - sizeof( ArrayHeader ) ) / sizeof(Token)
);
defines_map_arena = Arena_256KB::init();
defines = HashTable<StrC>::init_reserve( defines_map_arena, 256 );
fixed_arena_init(defines_map_arena);
defines = HashTable<StrC>::init_reserve( allocator_info(defines_map_arena), 256 );
}
internal
@ -713,8 +713,8 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
local_persist
char interface_arr_mem[ kilobytes(4) ] {0};
Array<CodeType> interfaces; {
Arena arena = init_from_memory( interface_arr_mem, kilobytes(4) );
Array<CodeType>::init_reserve( arena, 4 );
Arena arena = arena_init_from_memory( interface_arr_mem, kilobytes(4) );
array_init_reserve<CodeType>( allocator_info(arena), 4 );
}
// TODO(Ed) : Make an AST_DerivedType, we'll store any arbitary derived type into there as a linear linked list of them.