medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 8e63a85c27ce4688a3f063f74a3882db39d663a7
parent fd192f7e10d762503ee440f4447d00066c741b52
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Fri Jan  8 20:40:58 +0000

Use uintptr_t in MemoryArena

Diffstat:
intrinsics.h | 3+++
memory_arena.cc | 8++++----
memory_arena.h | 8++++----
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/intrinsics.h b/intrinsics.h @@ -15,6 +15,9 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; +typedef intptr_t sptr; +typedef uintptr_t uptr; + typedef float f32; typedef double f64; diff --git a/memory_arena.cc b/memory_arena.cc @@ -7,10 +7,10 @@ void memarena_init( MemoryArena * const arena, u8 * const memory, const size_t s arena->used = 0; } -u8 * memarena_push_size( MemoryArena * const arena, const size_t size, const size_t alignment ) { - size_t mem_addr = ( size_t ) arena->memory; - size_t aligned_addr = align_TODO( mem_addr + arena->used, alignment ); - size_t new_used = size + ( aligned_addr - mem_addr ); +u8 * memarena_push_size( MemoryArena * const arena, const size_t size, const uptr alignment ) { + uptr mem_addr = ( uptr ) arena->memory; + uptr aligned_addr = align_TODO( mem_addr + arena->used, alignment ); + uptr new_used = size + ( aligned_addr - mem_addr ); assert( new_used <= arena->size ); assert( new_used >= arena->used ); diff --git a/memory_arena.h b/memory_arena.h @@ -5,9 +5,9 @@ struct MemoryArena { u8 * memory; - size_t size; - size_t used; - size_t num_checkpoints; + uptr size; + uptr used; + u32 num_checkpoints; }; struct MemoryArenaCheckpoint { @@ -26,7 +26,7 @@ struct MemoryArenaAutoCheckpoint { void memarena_init( MemoryArena * const arena, u8 * const memory, const size_t size ); -u8 * memarena_push_size( MemoryArena * const arena, const size_t size, const size_t alignment = sizeof( void * ) ); +u8 * memarena_push_size( MemoryArena * const arena, const size_t size, const uptr alignment = sizeof( void * ) ); #define memarena_push_type( arena, type, ... ) ( ( type * ) memarena_push_size( arena, sizeof( type ), ##__VA_ARGS__ ) ) #define memarena_push_many( arena, type, count, ... ) ( ( type * ) memarena_push_size( arena, sizeof( type ) * count, ##__VA_ARGS__ ) )