ic_memory/runtime/config.rs
1use std::num::NonZeroU16;
2
3///
4/// MemoryManagerConfig
5///
6/// Immutable bucket allocation policy for a runtime. The default remains 128
7/// Wasm pages (8 MiB). Smaller sizes trade less rounding slack for a lower
8/// 32,768-bucket capacity and more frequent growth. This policy is separate
9/// from application allocation authorization and never grants memory access.
10///
11/// Explicit construction checks existing memory for an exact match before any
12/// effects. This is a same-release setting, not a migration or shrink operation.
13///
14
15#[derive(Clone, Copy, Debug, Eq, PartialEq)]
16pub struct MemoryManagerConfig {
17 bucket_size_pages: NonZeroU16,
18}
19
20impl Default for MemoryManagerConfig {
21 fn default() -> Self {
22 Self {
23 bucket_size_pages: NonZeroU16::new(128).unwrap(),
24 }
25 }
26}
27
28impl MemoryManagerConfig {
29 pub(super) const fn from_validated(bucket_size_pages: u16) -> Self {
30 Self {
31 bucket_size_pages: NonZeroU16::new(bucket_size_pages)
32 .expect("validated nonzero bucket size"),
33 }
34 }
35
36 /// Bind an already nonzero bucket size before construction effects.
37 #[must_use]
38 pub const fn new(bucket_size_pages: NonZeroU16) -> Self {
39 Self { bucket_size_pages }
40 }
41
42 /// Return the requested bucket size in pages.
43 #[must_use]
44 pub const fn bucket_size_pages(self) -> u16 {
45 self.bucket_size_pages.get()
46 }
47}