jemalloc-based memory allocator for ckit/rbase
Mem MemJEMalloc()provides a shared generic, thread-safe allocator.Mem MemJEMallocArenaAlloc()provides arena allocators.
Build & run example.c program with ckit:
ckit watch -r jemalloc-example
auto mem = MemJEMalloc();
void* a = memalloc(mem, size);
void* b = memalloc(mem, size);
// use a and b
memfree(mem, a);
memfree(mem, b);Note on runtime overhead: When compiling with a modern version of GCC or Clang, the above becomes direct calls to
je_callocandje_free, eliminating any overhead.
auto mem = MemJEMallocArenaAlloc(0);
void* a = memalloc(mem, size);
void* b = memalloc(mem, size);
// use a and b
MemJEMallocArenaFree(ma1); // free all memory allocated in the arena