Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexeychirkov
Last active June 18, 2021 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeychirkov/bd8a7afe8d4c85e3858efc59e07d5be7 to your computer and use it in GitHub Desktop.
Save alexeychirkov/bd8a7afe8d4c85e3858efc59e07d5be7 to your computer and use it in GitHub Desktop.
import Array "mo:base/Array";
import Iter "mo:base/Iter";
import Nat64 "mo:base/Nat64";
import Prim "mo:prim";
actor {
type CanisterMemoryInfo = {
rts_version : Text;
rts_memory_size: Nat;
rts_heap_size: Nat;
rts_total_allocation: Nat;
rts_reclaimed : Nat;
rts_max_live_size : Nat;
};
let initialSize = 1_000_000;
var store: [var Nat64] = Array.init<Nat64>(initialSize, 0);
public query func getSize() : async Nat {
store.size()
};
public query func getCanisterMemoryInfo() : async CanisterMemoryInfo {
return {
rts_version = Prim.rts_version();
rts_memory_size = Prim.rts_memory_size();
rts_heap_size = Prim.rts_heap_size();
rts_total_allocation = Prim.rts_total_allocation();
rts_reclaimed = Prim.rts_reclaimed();
rts_max_live_size = Prim.rts_max_live_size();
};
};
public func destroyArray() : async (Nat, CanisterMemoryInfo) {
store := Array.thaw([]);
(store.size(), await getCanisterMemoryInfo())
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment