Heap vs stable memory

I have data saved in a Hashmap and as I know it cannot be stable, so I solved the issue when I am updating the canister by using the system pre and post hooks and copy the data into a stable array and in the post update I copy it back to the heap. Now here is my guess of the issue, is it correct that, the heap saves MAX 2GB data while the stable can save upp to 400GB? In this case I need redesign my solution

1 Like

The maximum data storage size of stable memory of a canister is up 400 GB. The maximum data storage size of heap memory of a canister is up to 4 GB.

Check this out.

hi jaxopaxo

your let hashmap (normal variable) is heap (max 4GB).
your stable var array (stable variable) is still heap (max 4GB), and will turn into stable memory once your canister is dead (max 400GB)… and will turn into heap again (max 4GB) once your canister is upgraded and running.

regarding heap, even though it is maxed at 4GB, it is recommended to limit it at ~2GB because the process of converting your data from stable memory to stable variable already took similar amount/size of your data. Storing more than ~2GB will cause your upgrade to fail, which is as good as dead…

how i do it is i use stable var ... to store the list/array of ids/keys, but Region.mo to store the actual big data the ids represents. Based on the documentation here, you can max it out to 96GB (default 4 GB) since not all nodes support 400GB.