From 389e3a1e44a6e29655dd13b63132aa12dd6620d4 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Fri, 17 May 2024 16:37:15 -0700 Subject: baseline buddy allocator --- lua_benchmark/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lua_benchmark/main.c') diff --git a/lua_benchmark/main.c b/lua_benchmark/main.c index ddcf2fe..9ad2cc1 100644 --- a/lua_benchmark/main.c +++ b/lua_benchmark/main.c @@ -117,6 +117,30 @@ void *calloc(size_t cnt, size_t size) { return (void*)data; } +#elif defined(ALLOC_BASELINE_BUDDY) + +#define BUDDY_ALLOC_IMPLEMENTATION +#include "baselines/buddy_alloc.h" + +const size_t POOL_SIZE = 1024 * 1024 * 1024; +struct buddy *BUDDY; +void *POOL; + +static void init_allocator() { + /* You need space for arena and builtin metadata */ + POOL = malloc(POOL_SIZE); + BUDDY = buddy_embed(POOL, POOL_SIZE); +} + +static void *allocator_fn(void *ud, void *ptr, size_t osize, size_t nsize) { + // https://www.lua.org/manual/5.4/manual.html#4.6 + if (nsize == 0) { + buddy_free(BUDDY, ptr); + return NULL; + } + return buddy_realloc(BUDDY, ptr, nsize, 0); +} + #elif defined(ALLOC_SYSTEM) static void init_allocator() { } -- cgit v1.2.3