pub struct BoGlobalAllocator { /* private fields */ }Expand description
A stable GlobalAlloc adapter for using bomalloc as Rust’s process allocator.
The adapter is const-constructible and lazily creates its BoAllocator, so
it can be installed directly on a static:
use bomalloc::BoGlobalAllocator;
#[global_allocator]
static GLOBAL: BoGlobalAllocator = BoGlobalAllocator::new();
fn main() {
let values = vec![1_u64, 2, 3];
assert_eq!(values.iter().sum::<u64>(), 6);
}Allocations made recursively while bomalloc is initializing or managing its
own metadata use System. Deallocation routes such pointers back to System
by checking whether the address belongs to a bomalloc reservation. If the
configured allocator cannot initialize, this adapter remains usable by
falling back to System; Self::initialize exposes the initialization error.
Rust’s Allocator trait is still unstable on the crate’s Rust 1.86 baseline;
GlobalAlloc is the stable interface for replacing Rust’s global allocator.
Implementations§
Source§impl BoGlobalAllocator
impl BoGlobalAllocator
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a lazily initialized global allocator with Config::new.
Sourcepub const fn with_config(config: Config) -> Self
pub const fn with_config(config: Config) -> Self
Creates a lazily initialized global allocator with a custom configuration.
Sourcepub fn initialize(&self) -> Result<(), BoAllocError>
pub fn initialize(&self) -> Result<(), BoAllocError>
Initializes the process allocator, if necessary.
Sourcepub fn stats(&self) -> Result<StatsSnapshot, BoAllocError>
pub fn stats(&self) -> Result<StatsSnapshot, BoAllocError>
Returns a synchronized snapshot of the installed allocator’s statistics.
Sourcepub fn trim(&self, mode: TrimMode) -> Result<TrimStats, BoAllocError>
pub fn trim(&self, mode: TrimMode) -> Result<TrimStats, BoAllocError>
Cooperatively trims the installed allocator.
Sourcepub fn validate(&self) -> Result<(), InvariantError>
pub fn validate(&self) -> Result<(), InvariantError>
Validates the installed allocator’s debug invariants.
Trait Implementations§
Source§impl Default for BoGlobalAllocator
impl Default for BoGlobalAllocator
Source§impl GlobalAlloc for BoGlobalAllocator
impl GlobalAlloc for BoGlobalAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read moreSource§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
alloc, but also ensures that the contents
are set to zero before being returned. Read more