diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-24 09:19:41 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-24 09:19:41 +0100 |
| commit | 5cb7df67220e6d34c2456e3e51a839df9acb87b0 (patch) | |
| tree | aa08d00ca181c1ea27092ba543f6a1223e2a1bfc /README.md | |
| parent | db8d25f96f137c2ba170ea3caa9c2ad6a3dce40e (diff) | |
allocator configuration
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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", |
