Function ic_stable_memory::stable_memory_pre_upgrade
source · pub fn stable_memory_pre_upgrade() -> Result<(), OutOfMemory>Expand description
Persists the memory allocator into stable memory between canister upgrades.
See also stable_memory_post_upgrade.
This function should be called as the last step of the #[pre_ugrade] canister method.
It works by first writing the allocator to an SBox and then writing a pointer to that SBox into
frist 8 bytes of stable memory (offsets [0..8)). thread_local! static variable that stores the
allocator also gets cleared, if this function is executed successfully.
If it was impossible to allocate a memory block of required size, this function returns an OutOfMemory error. For tips on possible ways of resolving an OutOfMemory error visit this page.
This function is an alias for deinit_allocator().
Example
#[ic_cdk_macros::pre_upgrade]
fn pre_upgrade() {
// other pre-upgrade routine
if stable_memory_pre_upgrade().is_err() {
panic!("Out of stable memory")
}
}Panics
Panics if there is no initialized stable memory allocator.