Zig allocator backed by jemalloc.
zig fetch --save=jemalloc https://github.com/jiacai2050/zig-jemalloc/archive/${COMMIT}.tar.gz
Replace ${COMMIT}
with a real one, then in your build.zig
, import the module like this:
const dep_jemalloc = b.dependency("jemalloc", .{});
exe.root_module.addImport("jemalloc", dep_jemalloc.module("jemalloc"));
exe.linkLibC();
This library will link to vendored jemalloc(5.3.0) by default, you can disable this feature and link to the system-wide version using:
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();
Then in you main.zig
, initialize like this:
const jemalloc = @import("jemalloc");
const allocator = jemalloc.allocator;