Skip to main content

canic_core/memory/
mod.rs

1//! Module: memory
2//!
3//! Responsibility: adapt Canic stable-memory declarations to `ic-memory` bootstrap.
4//! Also owns physical stable-memory extent observation for runtime metrics.
5//! Does not own: stable data schemas, ops storage APIs, or lifecycle orchestration.
6//! Boundary: lifecycle initializes this before stable structures are accessed.
7
8pub(crate) mod ledger;
9mod policy;
10pub mod registry;
11pub mod runtime;
12
13pub use crate::{eager_init, eager_static, ic_memory_key, ic_memory_range};
14
15/// Stable allocation-policy authority for Canic core memory declarations.
16pub const CANIC_CORE_MEMORY_AUTHORITY: &str = "canic-core";
17/// Stable allocation-policy authority for Canic control-plane memory declarations.
18pub const CANIC_CONTROL_PLANE_MEMORY_AUTHORITY: &str = "canic-control-plane";
19
20/// Observe the current physical stable-memory extent without allocating or reading data.
21#[cfg(target_arch = "wasm32")]
22pub(crate) fn stable_extent_bytes() -> u64 {
23    ic_cdk::api::stable_size().saturating_mul(65_536)
24}
25
26pub(crate) fn bootstrap_default_memory_manager()
27-> Result<(), ic_memory::RuntimeBootstrapError<registry::MemoryRegistryError>> {
28    ic_memory::bootstrap_default_memory_manager_with_policy(&policy::CanicMemoryManagerPolicy::new())
29        .map(|_| ())
30}