import
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#ifndef INCLUDED_ARENA_H
|
||||
#define INCLUDED_ARENA_H
|
||||
|
||||
#ifndef INCLUDED_OS_TYPES_H
|
||||
#include <os_types.h>
|
||||
#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 temp_arena_memory_t {
|
||||
arena_t *arena;
|
||||
size_t prev_offset;
|
||||
size_t curr_offset;
|
||||
}temp_arena_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);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
temp_arena_memory_t temp_arena_memory_begin(arena_t *a);
|
||||
|
||||
void temp_arena_memory_end(temp_arena_memory_t temp);
|
||||
|
||||
#endif /*INCLUDED_ARENA_H*/
|
||||
Reference in New Issue
Block a user