Ecosyste.ms: Awesome

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

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

Zig allocator based on jemalloc
https://github.com/jiacai2050/zig-jemalloc

Last synced: about 1 month ago
JSON representation

Zig allocator based on jemalloc

Lists

README

        

#+TITLE: zig-jemalloc
#+DATE: 2024-04-03T16:31:20+0800
#+LASTMOD: 2024-04-03T23:43:34+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]]

Zig memory allocator based on [[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 a vendored [[https://github.com/jemalloc/jemalloc/releases/tag/5.3.0][jemalloc(5.3.0)]] by default, you can disable it and link to system-wide with this:
#+begin_src zig
const dep_jemalloc = b.dependency("jemalloc", .{ .link_vendor = false });
// brew install jemalloc
// 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