Shorter names
This commit is contained in:
+11
-9
@@ -6,9 +6,9 @@
|
||||
typedef struct MArena MArena;
|
||||
struct MArena {
|
||||
U8 *base; // start of buffer
|
||||
U32 first_free; // next alloc point
|
||||
U32 first_free;
|
||||
U32 size;
|
||||
S32 checkpoint_level; // level of marena_temp_begin nesting
|
||||
S32 temp_level; // level of marena_temp_begin nesting
|
||||
};
|
||||
|
||||
typedef struct MTemp MTemp;
|
||||
@@ -18,7 +18,7 @@ struct MTemp {
|
||||
};
|
||||
|
||||
#define MARENA_STATIC_INITIALIZER(data) MARENA_INITIALIZER((data), sizeof(data))
|
||||
#define MARENA_INITIALIZER(data, size_) {.base = (data), .first_free = 0, .size = (U32)size_, .checkpoint_level = 0}
|
||||
#define MARENA_INITIALIZER(data, size_) {.base = (data), .first_free = 0, .size = (U32)size_, .temp_level = 0}
|
||||
#define MARENA_DEFINE(var_name, size, alignment_) \
|
||||
struct { \
|
||||
_Alignas(alignment_) U8 memory[size];\
|
||||
@@ -41,7 +41,7 @@ static INLINE MTemp marena_temp_begin(MArena *arena)
|
||||
|
||||
checkpoint.arena = arena;
|
||||
checkpoint.offset = arena->first_free;
|
||||
arena->checkpoint_level++;
|
||||
arena->temp_level++;
|
||||
|
||||
return checkpoint;
|
||||
}
|
||||
@@ -49,13 +49,15 @@ static INLINE MTemp marena_temp_begin(MArena *arena)
|
||||
static INLINE void marena_temp_end(MTemp *state)
|
||||
{
|
||||
MArena *arena = state->arena;
|
||||
Assert(arena->checkpoint_level > 0);
|
||||
Assert(arena->temp_level > 0);
|
||||
arena->first_free = state->offset;
|
||||
arena->checkpoint_level--;
|
||||
arena->temp_level--;
|
||||
}
|
||||
|
||||
#define marena_push_type(allocator, type_) marenaalloc_aligned((allocator), sizeof(type_), _Alignof(type_))
|
||||
#define marena_push_array(allocator, type_, nr_elements_) marenaalloc_aligned((allocator), (nr_elements_) * (U32)sizeof(type_), _Alignof(type_))
|
||||
#define marena_push_type(allocator, type_)\
|
||||
marenaalloc_aligned((allocator), sizeof(type_), _Alignof(type_))
|
||||
#define marena_push_array(allocator, type_, nr_elements_)\
|
||||
marenaalloc_aligned((allocator), (nr_elements_) * (U32)sizeof(type_), _Alignof(type_))
|
||||
|
||||
|
||||
static INLINE void *marena_push(MArena *arena, U32 size)
|
||||
@@ -74,7 +76,7 @@ static INLINE void *maren_push_aligned(MArena *arena, U32 size, U32 align)
|
||||
Assert(IsPow2(align));
|
||||
|
||||
U32 aligned = AlignUp(arena->first_free, align);
|
||||
if (aligned < arena->first_free) { // align wrapped
|
||||
if (aligned < arena->first_free) { // aligned wrapped around
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user