How to tell which allocator I am using?


I’ve attempted to specify the system allocator with:


but massif is showing very little memory use anyhow. How can I verify that I really am using the system malloc?


The allocator is selected with extern crate alloc_system - the feature attribute just tells the compiler to disable the stability error.


nm target/foo/bar | grep jemalloc should do the trick.


Thanks, @sfackler and @birkenfeld, I’ve now gotten my code to use the system allocator so I can profile it’s memory use! :slight_smile:


@droundy I’m trying to get a simple Hello, World! application to build on the latest nightly Rust on macOS using the system allocator rather than jemalloc. I’ve been trying to read through the various different iterations of this feature to figure out what the current syntax is to no avail.

Would you be able to share a small stub that you used to get this working?


For anyone else that came here looking for an answer, see Inicola’s answer on GitHub for a solution.

#![feature(global_allocator, allocator_api)]

extern crate alloc_system;

use alloc_system::System;

static A: System = System;

fn main() {
    let a = Box::new(4); // Allocates from the system allocator.
    println!("Hello World!, {}", a);

Confirmed this worked on macOS rustc 1.22.0-nightly (981ce7d8d 2017-09-03).

Why is Hello World 4MB?
Xargo build cross compiler for armv5te (tier 3)
Default_lib_allocator info?
What is the smallest unit for static linking?