From 832bafccff577246dde2d11c23582f6a644c6c94 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 13 Mar 2024 23:18:29 +0500 Subject: Refactored Memory, Removed Strings --- memory/memory.h | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'memory/memory.h') diff --git a/memory/memory.h b/memory/memory.h index 14504b4..94b5022 100644 --- a/memory/memory.h +++ b/memory/memory.h @@ -7,16 +7,19 @@ #include #ifndef AMR_TYPES_H +#define AMR_TYPES_H -typedef int8_t S8; -typedef int16_t S16; -typedef int32_t S32; -typedef int64_t S64; +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; +typedef int64_t s64; -typedef uint8_t U8; -typedef uint16_t U16; -typedef uint32_t U32; -typedef uint64_t U64; +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef u8 b8; #endif // AMR_TYPES_H @@ -30,19 +33,19 @@ typedef uint64_t U64; enum MemStatus { MEM_OK=0, MEM_OUT_OF_BOUNDS, MEM_FULL }; -struct res_void { +struct ResVoid { enum MemStatus status; size_t bytes_count; void* memory; }; -bool is_power_of_two(uintptr_t x); +b8 is_power_of_two(uintptr_t x); //=========================================================================================== // ---------------------------------- ARENA ------------------------------------------------- //=========================================================================================== -struct arena { +struct Arena { unsigned char* buffer; size_t prev_offset; size_t curr_offset; @@ -50,14 +53,14 @@ struct arena { }; uintptr_t align_forward(uintptr_t ptr, size_t align); -void arena_init(struct arena *a, unsigned char *backing_store, size_t capacity); -void* arena_alloc_aligned(struct arena* a, size_t size, size_t align); -void* arena_alloc(struct arena* a, size_t size); -void* arena_resize_aligned(struct arena* a, void* old_memory, size_t old_size, +void arena_init(struct Arena *a, unsigned char *backing_store, size_t capacity); +void* arena_alloc_aligned(struct Arena* a, size_t size, size_t align); +void* arena_alloc(struct Arena* a, size_t size); +void* arena_resize_aligned(struct Arena* a, void* old_memory, size_t old_size, size_t new_size, size_t align); -void* arena_resize(struct arena* a, void* old_mem, size_t old_size, +void* arena_resize(struct Arena* a, void* old_mem, size_t old_size, size_t new_size); -void arena_clear(struct arena *a); +void arena_clear(struct Arena *a); //=========================================================================================== // ---------------------------------- STACK ------------------------------------------------- @@ -82,13 +85,13 @@ struct stack_hdr { size_t padding; }; -void stack_init(struct stack* s, void *backing_store, size_t capacity); -struct res_void stack_alloc_aligned(struct stack* s, size_t size, size_t alignment); -struct res_void stack_alloc(struct stack* s, size_t size); +void stack_init(struct stack* s, void *backing_store, size_t capacity); +struct ResVoid stack_alloc_aligned(struct stack* s, size_t size, size_t alignment); +struct ResVoid stack_alloc(struct stack* s, size_t size); enum MemStatus stack_free(struct stack* s); -struct res_void stack_resize_aligned(struct stack* s, void* old_memory, size_t old_size, +struct ResVoid stack_resize_aligned(struct stack* s, void* old_memory, size_t old_size, size_t new_size, size_t alignment); -struct res_void stack_resize(struct stack* s, void* old_memory, size_t old_size, size_t new_size); -void stack_clear(struct stack* s); +struct ResVoid stack_resize(struct stack* s, void* old_memory, size_t old_size, size_t new_size); +void stack_clear(struct stack* s); #endif -- cgit v1.2.3