From 5cb7df67220e6d34c2456e3e51a839df9acb87b0 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 24 Mar 2026 09:19:41 +0100 Subject: allocator configuration --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 17df1cf..759b7d0 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,23 @@ bool compare_string(const uint8_t* key1, const uint8_t* key2, uint8_t* user) { return strcmp(*(const char**)key1, *(const char**)key2) == 0; } +// Default allocator (uses malloc) +void* default_alloc(uintptr_t size, uint8_t* user) { + (void)user; + return malloc(size); +} + +// Default deallocator (uses free) +void default_dealloc(void* ptr, uint8_t* user) { + (void)user; + free(ptr); +} + int main(void) { // Create a map: string -> int (word frequency counter) struct cheesemap map; - cm_new_(&map, const char*, int, NULL, hash_string, compare_string); + cm_new_(&map, const char*, int, NULL, hash_string, compare_string, + default_alloc, default_dealloc); // Count word frequencies const char* words[] = {"hello", "world", "hello", -- cgit v1.2.3