Stream: wasmtime

Topic: what's the proper mechanism to pass a string into wasm?


view this post on Zulip Vladimir Pouzanov (Jan 18 2022 at 12:46):

it seems to me that I need to take my memory, grow it for the string's utf8 length, write the string bytes into that memory and pass the address and length down to the wasm function. Is this the recommended approach?

view this post on Zulip Alex Crichton (Jan 18 2022 at 15:29):

The future-facing answer for this questions is "interface types will make this much easier" along the lines of the wit-bindgen project. Otherwise though the general mechanism typically used for this is that the wasm module exposes a memory allocation function (e.g. malloc) and that's called to reserve space, the string is copied in, and then another wasm function is called.

view this post on Zulip Alex Crichton (Jan 18 2022 at 15:30):

You probably don't want to grow memory because then there's no great way for that memory to be reclaimed and memory can only be grown in units of 64k bytes at a time

view this post on Zulip Vladimir Pouzanov (Jan 18 2022 at 16:21):

yeah, that seems to match my conclusions, thanks. Oddly enough I picked AssemblyScript as my initial guest language and it's one of those that doesn't have a malloc and instead uses GC shenanigans.


Last updated: Nov 22 2024 at 16:03 UTC