Stable memory flag

how to use the stable memory flag : “–max-stable-pages” ?
docs

3 Likes

i really want to know it too

The Experimental StableMemory library and motoko stable variables (if any) both share the current 8GB max of IC stable memory available to a canister.

For now , we let the library use at most half this space (65536 * 64kb = 4GB) to leave space for stable variables. You can allow more or less pages for the library by specifying the command line option. Default is 65536.

1 Like

The ExperimentalStableMemory library :: Internet Computer is an example (not yet linked from site navigation)

1 Like

How to specify the flag? I tried it but failed.
command :
dfx build --–max-stable-pages 2147483648

For this thread:

For now , we let the library use at most half this space (65536 * 64kb = 4GB) to leave space for stable variables. You can allow more or less pages for the library by specifying the command line option. Default is 65536.

If I use the stable memory by using Experimental StableMemory Library and use the default model, the system upgrade functions will also make sense, right?

The option is an option to the moc compiler, not dfx. For dfx, you can specify moc options in an “args” entry for the canister in dfx.json. Sorry, I don’t have an example to hand.

And yes, you can use both stable variables and ESM.mo in the same canister, including pre/post upgrade methods.

I think the example above even does that if you look carefully.

3 Likes

Hello claudio, I have a new question about stable memory flag :
If I set the flag max-page-size to 6G, does the rest of the stable memroy (2G) still can be used for upgrading by using pre/postupgrade functions?

Yes, that’s the intention - the 2 GB will be reserved for storing stable variables during upgrade though they can use more if you haven’t allocated all the 6GB pages available to ExperimentalStableMemory.

To be perfectly honest, I’m not sure I tested this well enough (it was a last minute FR) and should add a test.

To be safe, it might be worth writing a little test program before you rely on this for something important.

I’ll file an issue to test this better. Tests: test max-stable-mem compiler option properly (unless we do already) · Issue #3065 · dfinity/motoko · GitHub

2 Likes

Ok! That’s really excellent ! I will test the api if I can upgrade my dfx(and moc), Thank you so much for your detail and perfect answer claudio !