summaryrefslogtreecommitdiff
path: root/lua_benchmark/main.c
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2024-05-17 16:37:15 -0700
committerMatthew Sotoudeh <matthew@masot.net>2024-05-17 16:37:15 -0700
commit389e3a1e44a6e29655dd13b63132aa12dd6620d4 (patch)
tree167fdf9558df46779349a0d8cd69b1551be8f09d /lua_benchmark/main.c
parent22f6857bc2c029d41b924c9dcb8c42ad7a57df68 (diff)
baseline buddy allocator
Diffstat (limited to 'lua_benchmark/main.c')
-rw-r--r--lua_benchmark/main.c24
1 files changed, 24 insertions, 0 deletions
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() { }
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback