From db32849ce314a93db01f877a057a91022fec7c8b Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 3 Sep 2024 00:48:18 +0300 Subject: added memory pool to reduce allocations 5x --- src/value.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/value.c') diff --git a/src/value.c b/src/value.c index 9a7f9b6..0d263d7 100644 --- a/src/value.c +++ b/src/value.c @@ -5,6 +5,12 @@ #include "value.h" #include "lexer.h" +#include "mempool.h" + +#define MEMPOOL_OBJ_TYPE struct value +#define MEMPOOL_CAP 64 +MEMPOOL_GENERATE(value) + #define NOT_IMPLEMENTED() die("Not Implemented. ABORTING") const char * const value_type_string[] = { @@ -76,7 +82,8 @@ static void proc_destroy(struct proc *proc); value_t value_create(enum value_type type, void *value) { - value_t _value = malloc(sizeof(*_value)); + // value_t _value = malloc(sizeof(*_value)); + value_t _value = value_mempool_allocate(); _value->type = type; switch(type) { @@ -98,7 +105,8 @@ void value_destroy(value_t value) } if(value->refs == 0) - free(value); + value_mempool_free(value); + // free(value); } value_t value_from_token(struct token *token) -- cgit v1.2.3