mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
got past init
This commit is contained in:
+7
-1
@@ -14,7 +14,13 @@
|
||||
Arena*
|
||||
arena__alloc(ArenaParams params)
|
||||
{
|
||||
SPTR const header_size = align_pow2(size_of(Arena), MD_DEFAULT_MEMORY_ALIGNMENT);
|
||||
SPTR const varena_header_size = align_pow2(size_of(VArena), MD_DEFAULT_MEMORY_ALIGNMENT);
|
||||
SPTR const header_size = align_pow2(size_of(Arena), MD_DEFAULT_MEMORY_ALIGNMENT);
|
||||
|
||||
U64 const varena_reserve_size = VARENA_DEFAULT_RESERVE;
|
||||
|
||||
if (params.backing.proc == nullptr) params.backing = default_allocator();
|
||||
if (params.block_size == 0 ) params.block_size = ARENA_DEFAULT_BLOCK_SIZE;
|
||||
|
||||
// TODO(Ed): Do we need to be slapping the arena onto the memory now?
|
||||
// (its technically not needed a its no longer always backed by vmem)
|
||||
|
||||
+4
-1
@@ -29,7 +29,9 @@ struct ArenaParams
|
||||
U64 block_size; // If chaining VArenas set this to the reserve size
|
||||
};
|
||||
|
||||
/* NOTE(Ed): The original metadesk arena is a combination of several concepts into a single interface:
|
||||
#define ARENA_DEFAULT_BLOCK_SIZE VARENA_DEFAULT_RESERVE - align_pow2(size_of(VArena), MD_DEFAULT_MEMORY_ALIGNMENT)
|
||||
|
||||
/* NOTE(Ed): The original metadesk arena is a combination of several concepts into a single interface
|
||||
* An OS virtual memory allocation scheme
|
||||
* A arena 'block' of memory with segmented chaining of the blocks
|
||||
* A push/pop stack allocation interface for the arena
|
||||
@@ -151,6 +153,7 @@ force_inline void temp_end(TempArena temp) { arena_pop_to(temp.arena, temp.pos);
|
||||
|
||||
#ifndef MD_OVERRIDE_DEFAULT_ALLOCATOR
|
||||
// The default allocator for this base module is the Arena allocator with a VArena backing
|
||||
// NOTE(Ed): In order for this to work, either the os entry_point must have been utilized or os_init needs to be called.
|
||||
inline AllocatorInfo
|
||||
default_allocator()
|
||||
{
|
||||
|
||||
@@ -37,7 +37,6 @@ void
|
||||
log_msgf(LogMsgKind kind, char *fmt, ...) {
|
||||
if(log_active != 0)
|
||||
{
|
||||
// TODO(Ed): Review
|
||||
TempArena scratch = scratch_begin(0, 0);
|
||||
|
||||
va_list args;
|
||||
@@ -77,7 +76,6 @@ log_scope_end(Arena *arena)
|
||||
if(arena != 0)
|
||||
{
|
||||
for (each_enum_val(LogMsgKind, kind)) {
|
||||
// TODO(Ed): Review
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
String8
|
||||
result_unindented = str8_list_join(scratch.arena, &scope->strings[kind], 0);
|
||||
|
||||
+16
-5
@@ -83,11 +83,20 @@
|
||||
|
||||
// TODO(Ed): Review usage of memmove here...(I guess wanting to avoid overlap faults..)
|
||||
#ifndef memory_copy
|
||||
# if USE_VENDOR_MEMORY_OPS
|
||||
# define memory_copy(dst, src, size) memmove((dst), (src), (size))
|
||||
# if OS_WINDOWS
|
||||
void* memcpy_intrinsic(void* dest, const void* src, size_t count)
|
||||
{
|
||||
if (dest == NULL || src == NULL || count == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__movsb((unsigned char*)dest, (const unsigned char*)src, count);
|
||||
return dest;
|
||||
}
|
||||
# define memory_copy(dst, src, size) memcpy_intrinsic((dst), (src), (size))
|
||||
# else
|
||||
# define memory_copy(dst, src, size) mem_move((dst), (src), (size))
|
||||
#endif
|
||||
# define memory_copy(dst, src, size) memmove((dst), (src), (size))
|
||||
# endif
|
||||
#endif
|
||||
#ifndef memory_set
|
||||
# if USE_VENDOR_MEMORY_OPS
|
||||
@@ -197,8 +206,10 @@ void* mem_move( void* destination, void const* source, SSIZE byte_count )
|
||||
if ( dest_ptr == src_ptr )
|
||||
return dest_ptr;
|
||||
|
||||
if ( src_ptr + byte_count <= dest_ptr || dest_ptr + byte_count <= src_ptr ) // NOTE: Non-overlapping
|
||||
// NOTE: Non-overlapping
|
||||
if ( src_ptr + byte_count <= dest_ptr || dest_ptr + byte_count <= src_ptr ) {
|
||||
return memory_copy( dest_ptr, src_ptr, byte_count );
|
||||
}
|
||||
|
||||
if ( dest_ptr < src_ptr )
|
||||
{
|
||||
|
||||
@@ -302,6 +302,7 @@ varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_
|
||||
UPTR current_offset = vm->reserve_start + vm->commit_used;
|
||||
UPTR size_to_allocate = requested_size;
|
||||
UPTR to_be_used = vm->commit_used + size_to_allocate;
|
||||
assert(to_be_used < vm->reserve);
|
||||
|
||||
UPTR header_offset = vm->reserve_start - scast(UPTR, vm);
|
||||
|
||||
@@ -312,11 +313,11 @@ varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_
|
||||
SPTR reserve_left = vm->reserve - vm->committed;
|
||||
UPTR next_commit_size;
|
||||
if (vm->flags & VArenaFlag_LargePages) {
|
||||
next_commit_size = reserve_left > 0 ? vm->commit_size : scast(UPTR, align_pow2( -reserve_left, os_get_system_info()->large_page_size));
|
||||
next_commit_size = reserve_left > 0 ? md_max(vm->commit_size, size_to_allocate) : scast(UPTR, align_pow2( -reserve_left, os_get_system_info()->large_page_size));
|
||||
}
|
||||
else {
|
||||
next_commit_size = reserve_left > 0 ? vm->commit_size : scast(UPTR, align_pow2(abs(reserve_left), os_get_system_info()->page_size));
|
||||
}
|
||||
next_commit_size = reserve_left > 0 ? md_max(vm->commit_size, size_to_allocate) : scast(UPTR, align_pow2(abs(reserve_left), os_get_system_info()->page_size));
|
||||
}
|
||||
if (next_commit_size) {
|
||||
B32 commit_result = os_commit(vm, next_commit_size);
|
||||
if (commit_result == false) {
|
||||
@@ -325,7 +326,7 @@ varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_
|
||||
}
|
||||
}
|
||||
|
||||
allocated_mem = rcast(void*, current_offset + size_to_allocate);
|
||||
allocated_mem = rcast(void*, current_offset);
|
||||
vm->commit_used += size_to_allocate;
|
||||
}
|
||||
break;
|
||||
|
||||
+3
-14
@@ -533,7 +533,6 @@ str8_from_alloctor_s64(AllocatorInfo ainfo, S64 s64, U32 radix, U8 min_digits, U
|
||||
{
|
||||
String8 result = {0};
|
||||
if(s64 < 0) {
|
||||
// TODO(Ed): Review, we should just keep using thread scratch arenas (and provide them to teh context)
|
||||
U8 bytes[KB(8)];
|
||||
FArena scratch = farena_from_memory(bytes, size_of(bytes));
|
||||
String8 numeric_part = str8_from_allocator_u64(farena_allocator(scratch), (U64)(-s64), radix, min_digits, digit_group_separator);
|
||||
@@ -929,7 +928,6 @@ path_style_from_str8(String8 string) {
|
||||
void
|
||||
str8_path_list_resolve_dots_in_place(String8List* path, PathStyle style)
|
||||
{
|
||||
// TODO(Ed): Review
|
||||
TempArena scratch = scratch_begin(0, 0);
|
||||
String8MetaNode* stack = 0;
|
||||
String8MetaNode* free_meta_node = 0;
|
||||
@@ -1562,9 +1560,7 @@ indented_from_string(Arena* arena, String8 string)
|
||||
String8
|
||||
indented_from_string_alloc(AllocatorInfo ainfo, String8 string)
|
||||
{
|
||||
// TODO(Ed): Review, we should just keep using thread scratch arenas (and provide them to teh context)
|
||||
Arena* arena = arena_alloc(.backing = ainfo, .block_size = MB(1));
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = scratch_begin(0, 0);
|
||||
|
||||
read_only local_persist U8 indentation_bytes[] = " ";
|
||||
String8List indented_strings = {0};
|
||||
@@ -1595,7 +1591,6 @@ indented_from_string_alloc(AllocatorInfo ainfo, String8 string)
|
||||
|
||||
String8 result = str8_list_join_alloc(ainfo, &indented_strings, 0);
|
||||
scratch_end(scratch);
|
||||
arena_release(arena);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1655,9 +1650,7 @@ escaped_from_raw_str8(Arena* arena, String8 string)
|
||||
String8
|
||||
escaped_from_raw_str8_alloc(AllocatorInfo ainfo, String8 string)
|
||||
{
|
||||
// TODO(Ed): Review, we should just keep using thread scratch arenas (and provide them to teh context)
|
||||
Arena* arena = arena_alloc(.backing = ainfo, .block_size = MB(1));
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = scratch_begin(0, 0);
|
||||
|
||||
String8List parts = {0};
|
||||
U64 start_split_idx = 0;
|
||||
@@ -1697,7 +1690,6 @@ escaped_from_raw_str8_alloc(AllocatorInfo ainfo, String8 string)
|
||||
String8 result = str8_list_join_alloc(ainfo, &parts, &join);
|
||||
|
||||
scratch_end(scratch);
|
||||
arena_release(arena);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1755,9 +1747,7 @@ raw_from_escaped_str8(Arena* arena, String8 string)
|
||||
String8
|
||||
raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string)
|
||||
{
|
||||
// TODO(Ed): Review, we should just keep using thread scratch arenas (and provide them to teh context)
|
||||
Arena* arena = arena_alloc(.backing = ainfo, .block_size = MB(1));
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = scratch_begin(0, 0);
|
||||
|
||||
String8List strs = {0};
|
||||
U64 start = 0;
|
||||
@@ -1799,7 +1789,6 @@ raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string)
|
||||
|
||||
String8 result = str8_list_join_alloc(ainfo, &strs, 0);
|
||||
scratch_end(scratch);
|
||||
arena_release(arena);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1034,8 +1034,8 @@ MD_API String8List wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8
|
||||
////////////////////////////////
|
||||
//~ rjf: String <-> Color
|
||||
|
||||
inline String8 hex_string_from_rgba_4f32 (Arena* arena, Vec4F32 rgba) { String8 hex_string = push_str8f(arena, "%02x%02x%02x%02x", (U8)(rgba.x*255.f), (U8)(rgba.y*255.f), (U8)(rgba.z*255.f), (U8)(rgba.w*255.f)); return hex_string; }
|
||||
inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = alloc_str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x*255.f), (U8)(rgba.y*255.f), (U8)(rgba.z*255.f), (U8)(rgba.w*255.f)); return hex_string; }
|
||||
inline String8 hex_string_from_rgba_4f32 (Arena* arena, Vec4F32 rgba) { String8 hex_string = push_str8f (arena, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; }
|
||||
inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = alloc_str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; }
|
||||
|
||||
MD_API Vec4F32 rgba_from_hex_string_4f32(String8 hex_string);
|
||||
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ struct Context
|
||||
OS_Context os_ctx;
|
||||
|
||||
// This skips the os_init process but that means the user is expected to setup
|
||||
// the thread context for the process
|
||||
// the thread context's arenas for the process
|
||||
B32 dont_init_os;
|
||||
};
|
||||
|
||||
|
||||
+2
-1
@@ -5,9 +5,10 @@
|
||||
int main()
|
||||
{
|
||||
Context ctx = {0};
|
||||
ctx.os_ctx.enable_large_pages = true;
|
||||
init(& ctx);
|
||||
|
||||
|
||||
printf("metadesk: got past init!");
|
||||
|
||||
deinit(& ctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user