Getting heap and stable size

When utilizing heap and stable structure memory with the stable structure crate (https://github.com/dfinity/stable-structures), how can I determine the size of the heap and the stable memory separately?

While canister_status() seems to provide the overall memory usage, I’m interested in finding how to differentiate between the two.

Basically I want to display a user: total size zzzz Mb of which heap size xxxx Mb, stable size yyyy Mb.

Looks like there is ic_cdk::api::stable::stable_size (thanks @Manu!)

2 Likes

You can also get the size of the heap memory specifically using memory_size from the Rust standard library. Note that the return value is the size in Wasm pages.

2 Likes