What is in a Rust Allocator?
Recently I was reading the documentation for
jemalloc and wondered what actually
goes into a custom memory allocator for Rust. To add jemalloc, or any other
custom allocator, to a Rust application, one uses the
#[global_allocator]
macro. Conveniently, the documentation for
GlobalAlloc
actually has a full example allocator for us to explore. It starts out as
follows:
const ARENA_SIZE: usize = 128 * 1024;
const MAX_SUPPORTED_ALIGN: usize = 4096;
#[repr(C, align(4096))] // 4096 == MAX_SUPPORTED_ALI...
Read more at blog.sulami.xyz