Way to know allocated heap memory?

It would be great for some performace optimizations but also for avoiding canister death, if we could know how much heap memory is allocated. Is there a way to do this and I just missed it? I could of course track all loaded structures ( in rust ) but this would in itself add overhead and in any case it might be difficult in specific situations to know how much memory one instantiated struct is taking.
In any operating system I could just make a syscall and get it from whatever process watchdog it implements but in icp there doesn’t seem to be a way to do this currently.

1 Like

Wasm just has a big block of memory. The allocator is compiled into your Rust code like everything else; the IC has no knowledge of it. You would trace allocations by using a tracing allocator yourself, like wasm-tracing-allocator.

Thank you very much! Should have checked wasm spec.