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?
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.
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
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: Dec 23 2024 at 13:07 UTC