Skip to main content

bomalloc/
lib.rs

1//! `bomalloc` is an experimental, fragmentation-aware allocator.
2//!
3//! It can be used through the explicit [`BoAllocator`] API or installed as the
4//! process allocator through [`BoGlobalAllocator`]. The tree carves 64 KiB Black small spans;
5//! their steady owner alloc/free path is TLS-only, while cross-thread frees can
6//! remain in a bounded TLS Black cache before batched shared publication.
7//! OS-backed trim and chunk maintenance remain serialized.
8//!
9//! # Platform support
10//!
11//! The published crate targets x86-64 Windows and Linux on stable Rust 1.86 or
12//! newer. It is experimental and has not received an independent security audit.
13//!
14//! # Example
15//!
16//! ```
17//! use bomalloc::BoGlobalAllocator;
18//!
19//! #[global_allocator]
20//! static GLOBAL: BoGlobalAllocator = BoGlobalAllocator::new();
21//!
22//! let values = (0_u64..1_000).collect::<Vec<_>>();
23//! assert_eq!(values.len(), 1_000);
24//! ```
25
26#![deny(unsafe_op_in_unsafe_fn)]
27
28mod allocator;
29mod config;
30mod error;
31mod ffi;
32mod global;
33mod os;
34mod payload_vec;
35mod span;
36mod stats;
37mod tls;
38mod topology;
39
40pub use allocator::BoAllocator;
41pub use config::{
42    Config, DEFAULT_DEDICATED_COMMIT_CACHE_BYTES, MAX_ADAPTIVE_RUN_TERRITORY_EXTENSION_EXTENTS,
43    MAX_ADAPTIVE_TERRITORY_EXTENSION_SPANS, MAX_BLACK_SPAN_RING_CAPACITY,
44    MAX_LOCAL_MAGAZINE_CAPACITY, MAX_LOCALITY_WINDOW_SPANS, MAX_LOW_CAPACITY_PAGE_QUEUE_SPANS,
45    MAX_RECENT_FREE_WORD_HINTS, MAX_RECENT_SPANS_PER_CLASS, MAX_REMOTE_CACHE_CAPACITY,
46    MAX_RUN_LOCAL_WINDOW_CAPACITY, SIZE_CLASSES, TrimMode,
47};
48pub use error::{BoAllocError, InvariantError};
49pub use ffi::{
50    BoCStatsV1, BoCTrimStatsV1, bo_aligned_alloc, bo_allocator_abi_version,
51    bo_allocator_initialize, bo_allocator_stats_v1, bo_allocator_trim_v1, bo_allocator_validate,
52    bo_calloc, bo_free, bo_malloc, bo_malloc_usable_size, bo_posix_memalign, bo_realloc,
53    bo_reallocarray,
54};
55pub use global::BoGlobalAllocator;
56pub use stats::{StatsSnapshot, TrimStats};