ic-memory 0.63.1

Superseded by ic-storage. Legacy stable-memory allocation governance for Internet Computer canisters.
Documentation
use std::num::NonZeroU16;

///
/// MemoryManagerConfig
///
/// Immutable bucket allocation policy for a runtime. The default remains 128
/// Wasm pages (8 MiB). Smaller sizes trade less rounding slack for a lower
/// 32,768-bucket capacity and more frequent growth. This policy is separate
/// from application allocation authorization and never grants memory access.
///
/// Explicit construction checks existing memory for an exact match before any
/// effects. This is a same-release setting, not a migration or shrink operation.
///

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MemoryManagerConfig {
    bucket_size_pages: NonZeroU16,
}

impl Default for MemoryManagerConfig {
    fn default() -> Self {
        Self {
            bucket_size_pages: NonZeroU16::new(128).unwrap(),
        }
    }
}

impl MemoryManagerConfig {
    pub(super) const fn from_validated(bucket_size_pages: u16) -> Self {
        Self {
            bucket_size_pages: NonZeroU16::new(bucket_size_pages)
                .expect("validated nonzero bucket size"),
        }
    }

    /// Bind an already nonzero bucket size before construction effects.
    #[must_use]
    pub const fn new(bucket_size_pages: NonZeroU16) -> Self {
        Self { bucket_size_pages }
    }

    /// Return the requested bucket size in pages.
    #[must_use]
    pub const fn bucket_size_pages(self) -> u16 {
        self.bucket_size_pages.get()
    }
}