https://github.com/rsms/ckit-jemalloc
jemalloc-based memory allocator for ckit/rbase
https://github.com/rsms/ckit-jemalloc
arena-allocator ckit
Last synced: 9 months ago
JSON representation
jemalloc-based memory allocator for ckit/rbase
- Host: GitHub
- URL: https://github.com/rsms/ckit-jemalloc
- Owner: rsms
- License: isc
- Created: 2021-05-18T00:22:52.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-20T00:12:43.000Z (about 5 years ago)
- Last Synced: 2025-09-15T21:39:21.198Z (10 months ago)
- Topics: arena-allocator, ckit
- Language: C
- Homepage:
- Size: 682 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
jemalloc-based memory allocator for [ckit/rbase](https://github.com/rsms/ckit/blob/main/pkg/rbase/mem.h)
- `Mem MemJEMalloc()` provides a shared generic, thread-safe allocator.
- `Mem MemJEMallocArenaAlloc()` provides arena allocators.
## Examples
Build & run `example.c` program with [ckit](https://github.com/rsms/ckit):
ckit watch -r jemalloc-example
### Generic allocator example
```c
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
```c
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
```