Canister Memory Management & Data Memory Requirements

Hi

Curious to know if any api exists yet that accurately report on the current memory consumed by a canister from motoko or any other language?

Also do we have anything like sizeof to accurately provide the memory footprint for a piece of data?

Interested in trying to build out a sharding library that supports auto scaling canisters.

Thanks

2 Likes

You can use Prim.rts_heap_size() in Motoko to synchronously get a canister’s current heap memory.

Here’s an example of how I used it to build auto-scaling into CanDB - CanDB/src/CanDB.mo at d76760914f424bec8755bf15ece0fc491c1574ec · ORIGYN-SA/CanDB · GitHub

Feel free to take sharding ideas from that repo and concept as well.

1 Like