Skip to main content

mnemosyne_arena/
lib.rs

1//! Shared arena and segment management logic for Mnemosyne.
2
3#![cfg_attr(not(any(feature = "std", test)), no_std)]
4#![deny(missing_docs)]
5
6#[cfg(any(feature = "std", test))]
7extern crate std;
8
9extern crate alloc;
10
11pub mod arena;
12pub mod numa;
13pub mod scratch;
14pub mod segment;
15
16pub use arena::{allocate_large_or_huge, deallocate_large_or_huge};
17pub use numa::{bind_segment_to_numa_node, current_numa_node};
18pub use scratch::{
19    AlignedBuf, AlignedVec, DEFAULT_SCRATCH_ALIGN, Drain, IntoIter, ScratchBank, ScratchElement,
20    ScratchPool,
21};
22pub use segment::{
23    AcquiredSegment, ArenaMemoryStats, GlobalHugePool, GlobalSegmentPool, HasSegmentPool,
24    HugePoolStats, MAX_RETAINED_SEGMENTS, SEGMENT_MAPPING_SIZE, SegmentPoolStats, acquire_segment,
25    allocate_segment, arena_memory_stats, checked_align_up, deallocate_segment, purge_segment_pool,
26    purge_segment_pool_with_warm, reset_segment_pool, try_deallocate_segment,
27};
28
29/// Constructs an [`AlignedVec`] from a literal list of elements.
30///
31/// Syntax mirrors `vec!` from the standard library:
32/// - `aligned_vec![1u32, 2, 3]` — create from elements
33/// - `aligned_vec![0u8; 64]` — fill with `n` copies of a value
34///
35/// # Examples
36///
37/// ```rust
38/// use mnemosyne_arena::aligned_vec;
39/// let v = aligned_vec![1u32, 2, 3];
40/// assert_eq!(v.as_slice(), &[1, 2, 3]);
41///
42/// let zeros = aligned_vec![0u8; 8];
43/// assert_eq!(zeros.len(), 8);
44/// assert!(zeros.iter().all(|&b| b == 0));
45/// ```
46#[macro_export]
47macro_rules! aligned_vec {
48    () => {
49        $crate::AlignedVec::dangling()
50    };
51    ($elem:expr; $n:expr) => {
52        $crate::AlignedVec::filled($n, $elem)
53    };
54    ($($x:expr),+ $(,)?) => {{
55        let slice: &[_] = &[$($x),+];
56        $crate::AlignedVec::from_slice(slice)
57    }};
58}