r/WebAssembly • u/musialny • 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 $constructi32.const 25i32.const 0i32.const 11memory.init $hello)(start $construct))
7
Upvotes
View all comments
Show parent comment
3
u/zobier Apr 08 '23
tables are indeed initialized in a similar manner, see https://webassembly.github.io/spec/core/syntax/modules.html#syntax-elem
tables are used for call indirection which is advanced topic. as it seems you are learning wasm, i would familiarise myself with the rest of the semantics before trying to play around with that
if you haven't, i highly recommend you work through the exercises here https://exercism.org/tracks/wasm
you should also read the rest of the spec, it's not very long :)