How to tell which allocator I am using?


#1

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?


#2

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


#3

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


#4

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:


#5

@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?


#6

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).


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?