Skip to content

rsms/ckit-jemalloc

Repository files navigation

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

About

jemalloc-based memory allocator for ckit/rbase

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published