stable_memory_post_upgrade

Function stable_memory_post_upgrade 

Source
pub fn stable_memory_post_upgrade()
Expand description

Retrieves the memory allocator from stable memory.

See also stable_memory_pre_upgrade.

This function should be called as the first step of the #[post_upgrade] canister method.

The process is exactly the same as in stable_memory_pre_upgrade, but in reverse order. It reads first 8 bytes of stable memory to get a pointer. Then the SBox located at that pointer is read and “unboxed” into the allocator. Then the allocator is assigned back to the thread_local! variable.

This function is an alias for reinit_allocator().

§Example

use ic_stable_memory::stable_memory_post_upgrade;
#[ic_cdk_macros::post_upgrade]
fn post_upgrade() {
    stable_memory_post_upgrade();

    // other post-upgrade routine
}

§Panics

This function will panic if:

  1. there is no valid pointer stored at first 8 bytes of stable memory,
  2. there is no valid SBox was found at that location,
  3. deserialization step during SBox’s “unboxing” failed due to invalid data stored inside this SBox,
  4. if there was an already initialized stable memory allocator.