1use candid::CandidType;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, CandidType)]
8pub struct MemorySize {
9 heap: u64,
11 stable: u64,
13}
14
15impl MemorySize {
16 pub fn used() -> Self {
17 Self {
18 heap: wasm_memory_size(),
19 stable: bity_ic_stable_memory::used(),
20 }
21 }
22}
23
24pub fn wasm_memory_size() -> u64 {
26 #[cfg(target_arch = "wasm32")]
27 {
28 const UPPER_LIMIT_WASM_SIZE_BYTES: u64 = 3 * 1024 * 1024; UPPER_LIMIT_WASM_SIZE_BYTES + ((core::arch::wasm32::memory_size(0) * 65536) as u64)
30 }
31
32 #[cfg(not(target_arch = "wasm32"))]
33 {
34 1024 * 1024 * 100 }
37}