It used to be that you could use #![feature(alloc_jemalloc)]
to statically link a crate - even if the artifact was dynamic library - against jemalloc as the allocator. Unfortunately, rustc
no longer recognizes that feature. Is there a different way to do this now?
The global allocator interface has changed a bit: https://doc.rust-lang.org/nightly/unstable-book/language-features/global-allocator.html. TL;DR:
extern crate alloc_jemalloc;
use alloc_jemalloc::Jemalloc;
#[global_allocator]
static ALLOCATOR = Jemalloc;
Looks like there's unfortunately no Jemalloc
in alloc_jemalloc
- it looks like that crate is only implementing the old global allocator strategy: https://github.com/japaric/alloc-jemalloc/blob/master/src/lib.rs
The in-tree alloc-jemalloc implements the new interface: https://github.com/rust-lang/rust/blob/master/src/liballoc_jemalloc/lib.rs
Worked, thanks!
Oh, gotcha. It doesn't implement Alloc
, but rather provides its own global allocator so you just have to do extern crate alloc_jemalloc
and it Just Works. Thanks!
It's in a bit of a state of transition - the magical "just link to me" behavior is the old setup. On a sufficiently new compiler you'll need to do the tagged static thing. alloc_jemalloc has to implement both right now so things work with the bootstrap compiler.