/ckit-jemalloc

jemalloc-based memory allocator for ckit/rbase

Primary LanguageCISC LicenseISC

jemalloc-based memory allocator for ckit/rbase

  • Mem MemJEMalloc() provides a shared generic, thread-safe allocator.
  • Mem MemJEMallocArenaAlloc() provides arena allocators.

Examples

Build & run example.c program with ckit:

ckit watch -r jemalloc-example

Generic allocator 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_calloc and je_free, eliminating any overhead.

Arena allocator example

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