Stable memory pricing

Hey there.

I’m building a canister that includes both stable memory (ic-stable-structures), and heap (serialized into/from stable-memory via pre and post-upgrade hooks). My plan is to serialize into an unused page range during these update hooks. My questions relate to how stable memory is charged.

  1. Is it charged only related to the number of pages used(for on-going storage)/written to(for memory access during one call)? If I use pages [0…10, 10000…10010], do I get charged for 20 pages or 10010 pages?

  2. If I subsequently zero out pages [10000…10010], how much do I get charged for storage afterwards?

The answer to both these questions is that you’ll be charged for the full 10010 pages. But if you’re already using ic-stable-structures then this should be easily solved using the memory manager which was designed to fix this exact problem. You can use it to create two “memories” in stable memory and then you can use one of them for your permanent structures and the other for temporary storage during upgrades.