77 lines
1.9 KiB
C
77 lines
1.9 KiB
C
#ifndef INCLUDED_C_ARENA_H
|
|||
|
|
#define INCLUDED_C_ARENA_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_TYPES_H
|
||
|
|
#include <c_Types.h>
|
||
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_ALIGNMENT_H
|
||
|
|
#include <c_Alignment.h>
|
||
|
|
#endif /*INCLUDED_C_ALIGNMENT_H*/
|
||
|
|
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct c_Arena_s c_Arena_t;
|
||
|
|
struct c_Arena_s {
|
||
|
|
unsigned char *buf;
|
||
|
|
c_size_t buf_len;
|
||
|
|
c_size_t prev_offset; // This will be useful for later on
|
||
|
|
c_size_t curr_offset;
|
||
|
|
};
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
void c_Arena_Init(c_Arena_t *a, void *backing_buffer, size_t backing_buffer_length) {
|
||
|
|
a->buf = (unsigned char *)backing_buffer;
|
||
|
|
a->buf_len = backing_buffer_length;
|
||
|
|
a->curr_offset = 0;
|
||
|
|
a->prev_offset = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
void c_Arena_Destroy(c_Arena_t *a) {
|
||
|
|
a->curr_offset = 0;
|
||
|
|
a->prev_offset = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
void c_Arena_Free(c_Arena_t *a, void *ptr) {
|
||
|
|
C_UNUSED(a);
|
||
|
|
C_UNUSED(ptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
void *c_Arena_Alloc(c_Arena_t *a, c_size_t size);
|
||
|
|
|
||
|
|
void *c_Arena_Resize(c_Arena_t *a, void *old_memory, size_t old_size, size_t new_size);
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct c_ArenaTemp_s c_ArenaTemp_t;
|
||
|
|
struct c_ArenaTemp_s {
|
||
|
|
c_Arena_t *arena;
|
||
|
|
size_t prev_offset;
|
||
|
|
size_t curr_offset;
|
||
|
|
};
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_ArenaTemp_t c_ArenaTemp_Begin(c_Arena_t *a) {
|
||
|
|
c_ArenaTemp_t temp;
|
||
|
|
temp.arena = a;
|
||
|
|
temp.prev_offset = a->prev_offset;
|
||
|
|
temp.curr_offset = a->curr_offset;
|
||
|
|
return temp;
|
||
|
|
}
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
void c_ArenaTemp_End(c_ArenaTemp_t temp) {
|
||
|
|
temp.arena->prev_offset = temp.prev_offset;
|
||
|
|
temp.arena->curr_offset = temp.curr_offset;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_ARENA_H*/
|