Pool allocator
All checks were successful
Test and Deploy / test (push) Successful in 15s
Test and Deploy / docs (push) Successful in 18s

This commit is contained in:
2024-07-16 21:52:02 -07:00
parent 59fee5094b
commit c2fe01f04c
7 changed files with 243 additions and 33 deletions

View File

@ -3,6 +3,12 @@
#include <stddef.h>
#include "lflinkedlist.h"
#ifndef DEFAULT_ALIGNMENT
#define LF_DEFAULT_ALIGNMENT (2*sizeof(void*))
#endif // DEFAULT_ALIGNMENT
typedef struct {
unsigned char* buf;
size_t buf_sz;
@ -17,4 +23,20 @@ void arena_resize_buf(ArenaAllocator *allocator, size_t new_sz);
void *arena_resize(ArenaAllocator *allocator, void *mem, size_t old_sz, size_t new_sz);
void arena_clear(ArenaAllocator *allocator);
typedef struct {
unsigned char *buf;
size_t buf_sz;
size_t chunk_size;
List *free_list;
} PoolAllocator;
void pool_init(PoolAllocator *allocator, size_t buf_sz, size_t chunk_sz, size_t chunk_align);
void pool_free(PoolAllocator *allocator, void *ptr);
void pool_free_all(PoolAllocator *allocator);
void *pool_alloc(PoolAllocator *allocator);
void pool_destroy(PoolAllocator *allocator);
#define pool_count_available(x) (x)->free_list->size
#endif // LIBFLINT_H_MEMORY