How to tell which allocator I am using?

I've attempted to specify the system allocator with:

 #[feature(alloc_system)]

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.

1 Like

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

1 Like

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(alloc_system)]
#![feature(global_allocator, allocator_api)]

extern crate alloc_system;

use alloc_system::System;

#[global_allocator]
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).

4 Likes