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
Copy file name to clipboardExpand all lines: samples/custom_section/README.md
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,7 @@
2
2
description: "The related code/working directory of this example resides in directory {WAMR_DIR}/samples/custom_section"
3
3
---
4
4
5
-
The "custom_section" sample project
6
-
==============
5
+
# The "custom_section" sample project
7
6
8
7
This sample demonstrates how to:
9
8
@@ -21,8 +20,20 @@ The Wasm application is built from:
21
20
22
21
The assembler file emits a section named `.custom_section.demo`, which becomes a Wasm custom section named `demo` in the final `.wasm` file.
23
22
24
-
Build this sample
25
-
==============
23
+
## Why use a custom section for this payload
24
+
25
+
The payload in this sample is treated as read-only metadata. Putting it in a custom section lets the embedder access the bytes directly from the loaded module through `wasm_runtime_get_custom_section`, instead of copying the data into Wasm linear memory per instance.
26
+
27
+
That matters when the data is large or rarely changed:
28
+
29
+
- the bytes stay in the module image as immutable data
30
+
- the host can look them up by section name and use them in place
31
+
- the Wasm app only needs to pass a small section name and receive a small handle
32
+
- no extra application-level serialization or buffer duplication is needed for the read-only payload
33
+
34
+
This pattern is useful for embedded assets, lookup tables, model metadata, certificates, and other static blobs that the host wants to consume without treating them as mutable Wasm heap data.
35
+
36
+
## Build this sample
26
37
27
38
Execute the `build.sh` script. The host executable and the Wasm app are generated in `out`.
28
39
@@ -36,8 +47,7 @@ Build the AoT variant only when needed by passing `--aot`. This preserves the `d
36
47
./build.sh --aot
37
48
```
38
49
39
-
Run the sample
40
-
==========================
50
+
## Run the sample
41
51
42
52
Enter the output directory and run the Wasm sample directly:
43
53
@@ -57,5 +67,3 @@ To run the AoT artifact instead, pass `--aot` to the helper script:
57
67
```sh
58
68
./run.sh --aot
59
69
```
60
-
61
-
When running under WSL, use the Linux workspace path layout, for example `/home/tl/projects/wasm-micro-runtime/...`, not a Windows drive path.
0 commit comments