Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jiacai2050/zig-jemalloc

Zig allocator baked by jemalloc
https://github.com/jiacai2050/zig-jemalloc

zig-library zig-package

Last synced: 29 days ago
JSON representation

Zig allocator baked by jemalloc

Awesome Lists containing this project

README

        

#+TITLE: zig-jemalloc
#+DATE: 2024-04-03T16:31:20+0800
#+LASTMOD: 2024-10-16T08:45:54+0800
#+AUTHOR: Jiacai Liu

[[https://github.com/jiacai2050/zig-jemalloc/actions/workflows/CI.yml][https://github.com/jiacai2050/zig-jemalloc/actions/workflows/CI.yml/badge.svg]]
[[https://img.shields.io/badge/zig%20version-0.13.0-blue.svg]]
[[https://img.shields.io/badge/zig%20version-master-blue.svg]]

Zig allocator backed by [[https://jemalloc.net/][jemalloc]].

* Usage
#+begin_src shell
zig fetch --save=jemalloc https://github.com/jiacai2050/zig-jemalloc/archive/${COMMIT}.tar.gz
#+end_src

Replace ~${COMMIT}~ with a real one, then in your =build.zig=, import the module like this:
#+begin_src zig
const dep_jemalloc = b.dependency("jemalloc", .{});
exe.root_module.addImport("jemalloc", dep_jemalloc.module("jemalloc"));
exe.linkLibC();
#+end_src

This library will link to vendored [[https://github.com/jemalloc/jemalloc/releases/tag/5.3.0][jemalloc(5.3.0)]] by default, you can disable this feature and link to the system-wide version using:
#+begin_src zig
const dep_jemalloc = b.dependency("jemalloc", .{ .link_vendor = false });
// Install jemalloc with system package manager, such as
// brew install jemalloc
// sudo apt-get install libjemalloc-dev
exe.linkSystemLibrary("jemalloc");
exe.linkLibC();
#+end_src

Then in you =main.zig=, initialize like this:

#+begin_src zig
const jemalloc = @import("jemalloc");
const allocator = jemalloc.allocator;
#+end_src