#ifndef INCLUDED_ARENA_H #define INCLUDED_ARENA_H #ifndef INCLUDED_OS_TYPES_H #include #endif /*INCLUDED_OS_TYPES_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* https://www.gingerbill.org/article/2019/02/08/memory-allocation-strategies-002/ */ typedef struct arena_t{ uint8_t * buf; os_size_t buf_size; os_size_t prev_offset; os_size_t curr_offset; }arena_t; typedef struct arena_temp_memory_t { arena_t *arena; size_t prev_offset; size_t curr_offset; }arena_temp_memory_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ void arena_init(arena_t* self, uint8_t * buf, os_size_t buf_size); void* arena_alloc(arena_t* self, os_size_t size); void* arena_realloc(arena_t* self, void* old, os_size_t old_size, os_size_t new_size); // 不支持的操作 //void arena_free(arena_t* self, void* ptr); void arean_destroy(arena_t* self); /* ------------------------------------------------------------------------------------------------------------------ */ /* */ arena_temp_memory_t arena_temp_memory_begin(arena_t *a); void arena_temp_memory_end(arena_temp_memory_t temp); #endif /*INCLUDED_ARENA_H*/