Main purpose of my tests is to predict the memory allocation in Motoko.
I am running local replica using following command: dfx start --no-artificial-delay --clean
Array of Nat8’s
I am creating an array of 1_000_000 Nat8 number, so I expect that is it 1_000_000 * 1 byte = 1_000_000 bytes = should be around 1Mb in memory.
Main part of the source code: var store: [var Nat8] = Array.init<Nat8>(initialSize, 0);
Execution steps:
dfx deploy
-
dfx canister call test getCanisterMemoryInfo
Result:
(
record {
rts_max_live_size = 4_000_016;
rts_memory_size = 8_192_000;
rts_total_allocation = 4_000_140;
rts_heap_size = 4_000_052;
rts_reclaimed = 88;
rts_version = "0.1";
},
)
-
dfx canister call test getSize
Result:
(1_000_000)
-
dfx canister status test
Result:
Canister status call result for test.
Status: Running
Controller: rwlgt-iiaaa-aaaaa-aaaaa-cai
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(BigUint { data: [8364189] })
Balance: 4_000_000_000_000 Cycles
Module hash: 0x4ae83d59334f4a4ca501742de29e580e1390a468225fa6db4b53310c80ef21b0
Observations:
-
rts_memory_size
is 8_192_000 bytes -
Memory Size
from command line call is 8_364_189 bytes
So the main question is: why Array takes the same amount of memory as Array?