arena allocator
All checks were successful
Test and Deploy / test (push) Successful in 14s
Test and Deploy / docs (push) Successful in 19s

This commit is contained in:
2024-07-16 10:49:08 -07:00
parent 0c97ba45b1
commit 59fee5094b
15 changed files with 270 additions and 123 deletions

View File

@ -1,6 +1,8 @@
#ifndef LIBFLINT_H_MATH
#define LIBFLINT_H_MATH
#include <stddef.h>
#include "lfutility.h"
int max_int(int a, int b);
@ -11,6 +13,8 @@ int clamp_int(int i, int low, int high);
int binstr_to_int(const char *s);
int is_power_of_two(int i);
Point *bresenham(int x0, int y0, int x1, int y1, size_t *sz);
Point *bresenham_p(Point p1, Point p2, size_t *sz);

20
include/lfmemory.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef LIBFLINT_H_MEMORY
#define LIBFLINT_H_MEMORY
#include <stddef.h>
typedef struct {
unsigned char* buf;
size_t buf_sz;
size_t offset_cur;
size_t offset_prev;
} ArenaAllocator;
void arena_init(ArenaAllocator *allocator, size_t buf_sz);
void arena_free(ArenaAllocator *allocator);
void *arena_malloc(ArenaAllocator* allocator, size_t size);
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);
#endif // LIBFLINT_H_MEMORY