You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Internet Computer can automatically execute a special type of function called a low Wasm memory hook, which runs when the canister's available Wasm memory falls below the `wasm_memory_threshold`.
4
4
5
-
This Motoko example demonstrates using the low Wasm memory hook on ICP. If you're interested in how this example is implemented in Rust, check out the [Rust variation](../../rust/low_wasm_memory).
5
+
This Motoko example demonstrates using the low Wasm memory hook on ICP. For more information take a look at [low Wasm memory hook specification](https://internetcomputer.org/docs/references/ic-interface-spec#on-low-wasm-memory).
6
6
7
-
The example consists of a canister named `low_wasm_memory_hook` that increases usage of Wasm memory in every heartbeat execution until the low Wasm memory hook is run.
-[x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
13
-
-[x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
11
+
## Build and deploy from the command-line
14
12
15
-
##Using the example
13
+
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
16
14
17
-
In this example, the canister will periodically increase its memory usage (as defined in the `heartbeat` function) until the low Wasm memory hook is run
18
-
when the memory usage exceeds the `wasm_memory_threshold`.
15
+
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)
19
16
20
-
-#### Step 1: Setup project environment
17
+
###3. Navigate into the project's directory.
21
18
22
-
Navigate into the folder containing the project's files and start a local developer environment with the commands:
19
+
### 4. Deploy the project to your local environment:
23
20
24
-
```sh
25
-
cd examples/motoko/low_wasm_memory
26
-
dfx start --clean
27
-
```
28
-
29
-
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or the `dfx stop` command is run.
30
-
31
-
-#### Step 2: Open another terminal window in the same directory:
32
-
33
-
```sh
34
-
cd examples/motoko/low_wasm_memory
35
-
```
36
-
37
-
-#### Step 3: Create the `low_wasm_memory_hook` canister
38
-
39
-
```sh
40
-
dfx canister create low_wasm_memory_hook
41
-
```
42
-
43
-
Example output:
44
-
45
-
```sh
46
-
Created a wallet canister on the "local" network for user "default" with ID "uqqxf-5h777-77774-qaaaa-cai"
47
-
low_wasm_memory_hook canister created with canister id: uxrrr-q7777-77774-qaaaq-cai
48
-
```
49
-
50
-
-#### Step 4: Update canister settings
51
-
52
-
Update the canister's settings to modify the Wasm memory limit and threshold:
To repeat the example, you can redeploy the canister and reset its state with the following command:
133
-
134
-
```sh
135
-
dfx deploy low_wasm_memory_hook --mode reinstall
136
-
```
137
-
138
-
## Further learning
139
-
1. [Low memory hook](https://internetcomputer.org/docs/motoko/main/canister-maintenance/memory) in Motoko documentation
140
-
2. Have a look at the locally running dashboard. The URL is at the end of the `dfx start` command: `Dashboard: http://localhost:...`
141
-
3. Check out `low_wasm_memory_hook` canister's Candid user interface. The URLs are at the end of the `dfx deploy` command: `low_wasm_memory_hook: http://127.0.0.1:...`
142
-
143
-
### Canister interface
144
-
145
-
The `low_wasm_memory_hook` canister provides the following interface:
146
-
* `getExecutedFunctionsOrder` ; returns the vector with values of `FnType` (a variant with `#heartbeat` or `#onLowWasmMemory`) representing the order of functions executed.
For more information take a look at [low Wasm memory hook specification](https://internetcomputer.org/docs/references/ic-interface-spec#on-low-wasm-memory).
155
-
156
48
## Security considerations and best practices
157
-
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.
49
+
50
+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
0 commit comments