Kaltenberg/modules/utility/inc-c/voxula/internals/utility/allocation.h

53 lines
1.1 KiB
C

#ifndef VOXULA_ALLOCATOR_H
#define VOXULA_ALLOCATOR_H
#include <stdint.h>
typedef struct vx_pool vx_pool_s;
typedef struct vx_pool_slot_header vx_pool_slot_header_s;
typedef struct vx_arena vx_arena_s;
struct vx_pool_slot_header
{
vx_pool_slot_header_s *next;
vx_pool_s *pool;
};
struct vx_pool
{
uint32_t capacity;
uint32_t unit_size;
void *allocation;
vx_pool_slot_header_s *first_free;
vx_pool_s *continuation;
};
struct vx_arena
{
uint32_t capacity;
uint32_t usage;
void *allocation;
vx_arena_s *continuation;
};
// Pool Functions
vx_pool_s * vx_new_pool(uint32_t unit_size, uint32_t capacity);
void vx_free_pool(vx_pool_s *pool);
void * vx_pool(vx_pool_s *pool);
void vx_unpool(void *allocation);
// Arena Functions
vx_arena_s * vx_new_arena(uint32_t capacity);
void vx_free_arena(vx_arena_s *arena);
void * vx_arena_alloc(vx_arena_s *arena, uint32_t length);
char * vx_arena_dupe_string(vx_arena_s *arena, const char *string);
char * vx_arena_dupe_string_up_to(vx_arena_s *arena, const char *string, uint32_t maximum);
#endif // VOXULA_ALLOCATOR_H