rsms / ckit-jemalloc

jemalloc-based memory allocator for ckit/rbase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:ISC License


Languages

Language:C 83.0%Language:Perl 8.8%Language:M4 4.3%Language:C++ 1.5%Language:Makefile 1.1%Language:Shell 0.9%Language:Python 0.4%Language:XSLT 0.0%