From ff512986f8773fb440c4275dfdce8e6ca5debaa0 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 11 Feb 2026 07:56:34 +0000 Subject: [PATCH] symtable: sym_table_cost Useful for figuring out the rough memory footprint (actually utilised) by the symbol table. --- include/alisp/symtable.h | 3 +++ src/symtable.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/alisp/symtable.h b/include/alisp/symtable.h index c4012d3..4c85057 100644 --- a/include/alisp/symtable.h +++ b/include/alisp/symtable.h @@ -24,6 +24,9 @@ void sym_table_init(sym_table_t *); const char *sym_table_find(sym_table_t *, sv_t); void sym_table_free(sym_table_t *); +// Debugging function: total memory used by symbol table. +u64 sym_table_cost(sym_table_t *); + #endif /* Copyright (C) 2026 Aryadev Chavali diff --git a/src/symtable.c b/src/symtable.c index 5e5512c..e341a9e 100644 --- a/src/symtable.c +++ b/src/symtable.c @@ -72,6 +72,19 @@ void sym_table_free(sym_table_t *table) memset(table, 0, sizeof(*table)); } +u64 sym_table_cost(sym_table_t *table) +{ + if (!table || !table->count) + return 0; + else + { + u64 total_size = 0; + for (u64 i = 0; i < table->capacity; ++i) + total_size += ENTRY_GET(table, i).size; + return total_size; + } +} + /* Copyright (C) 2025, 2026 Aryadev Chavali * This program is distributed in the hope that it will be useful, but WITHOUT