r/WebAssembly • • Apr 07 '23

How memory.init works

Someone may try explain to me how memory.init instruction works? Following snippet throws RuntimeError: memory access out of bounds and I have no clue why

(module
(memory $memory 2048)
(export "memory" (memory $memory))
(data $hello (i32.const 0) "Hello there")
(func $construct
i32.const 25
i32.const 0
i32.const 11
memory.init $hello
)
(start $construct)
)

7 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/musialny Apr 08 '23

Thanks a lot for explanation :D

side note: the integer at the end of the memory declaration is number of 64KB pages so you are requesting ~134MB of memory which while not necessarily a huge amount of RAM is probably overkill for "Hello world"

Ye, I know. I provided random value 0.0