2024-01-19 21:05:57 +00:00
|
|
|
|
|
|
|
#ifndef RR_GENERIC_ALLOCATOR_H
|
|
|
|
#define RR_GENERIC_ALLOCATOR_H
|
|
|
|
|
|
|
|
#include <librr/types.h>
|
|
|
|
|
|
|
|
typedef struct rr_generic_allocator rr_generic_allocator_s;
|
|
|
|
typedef struct rr_generic_pool rr_generic_pool_s;
|
|
|
|
typedef struct rr_generic_arena rr_generic_arena_s;
|
|
|
|
|
|
|
|
typedef rr_generic_arena_s (*rr_create_arena_fn) (usz_t capacity);
|
|
|
|
typedef rr_generic_pool_s (*rr_create_pool_fn) (usz_t item_size, usz_t num_items);
|
|
|
|
|
|
|
|
struct rr_generic_allocator
|
|
|
|
{
|
|
|
|
void * (*fn_alloc) (rr_generic_allocator_s *allocator, usz_t num_bytes);
|
|
|
|
void (*fn_free) (rr_generic_allocator_s *allocator, void *block);
|
|
|
|
void (*fn_destruct) (rr_generic_allocator_s *allocator);
|
|
|
|
void *specifics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rr_generic_pool
|
|
|
|
{
|
|
|
|
void * (*fn_alloc) (rr_generic_pool_s *pool);
|
|
|
|
void (*fn_free) (rr_generic_pool_s *pool, void *block);
|
|
|
|
void (*fn_destruct) (rr_generic_pool_s *pool);
|
|
|
|
void *specifics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rr_generic_arena
|
|
|
|
{
|
|
|
|
void * (*fn_alloc) (rr_generic_arena_s *arena, usz_t num_bytes);
|
|
|
|
void (*fn_destruct) (rr_generic_arena_s *arena);
|
|
|
|
void *specifics;
|
|
|
|
};
|
|
|
|
|
2024-01-23 17:49:20 +00:00
|
|
|
void * rr_alloc(rr_generic_allocator_s *allocator, usz_t size);
|
|
|
|
void rr_free(rr_generic_allocator_s *allocator, void *allocation);
|
|
|
|
|
|
|
|
void * rr_arena_alloc(rr_generic_arena_s *arena, usz_t size);
|
|
|
|
|
|
|
|
void * rr_pool_alloc(rr_generic_pool_s *pool);
|
|
|
|
void rr_pool_free(rr_generic_pool_s *pool, void *allocation);
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __RR_AVOID_STDLIB
|
|
|
|
rr_generic_allocator_s rr_provide_stdlib_allocator();
|
|
|
|
#endif // __RR_AVOID_STDLIB
|
|
|
|
|
|
|
|
rr_generic_arena_s rr_provide_arena(rr_generic_allocator_s *allocator, usz_t len_allocation);
|
|
|
|
rr_generic_pool_s rr_provide_dynamic_pool(rr_generic_allocator_s *allocator, usz_t item_size, usz_t capacity);
|
|
|
|
rr_generic_pool_s rr_provide_static_pool(rr_generic_allocator_s *allocator, usz_t item_size, usz_t capacity);
|
|
|
|
|
|
|
|
rr_generic_arena_s rr_provide_arena_from_malloc(usz_t len_allocation);
|
|
|
|
rr_generic_pool_s rr_provide_dynamic_pool_from_malloc(usz_t item_size, usz_t capacity);
|
|
|
|
rr_generic_pool_s rr_provide_static_pool_from_malloc(usz_t item_size, usz_t capacity);
|
|
|
|
|
2024-01-19 21:05:57 +00:00
|
|
|
#endif // RR_GENERIC_ALLOCATOR_H
|
2024-01-23 17:49:20 +00:00
|
|
|
|