3 ms·
It seems strange for WASM to get a GC. Shouldn't it just expose a malloc and free call?
by dom96 5y ago
It seems strange for WASM to get a GC. Shouldn't it just expose a malloc and free call?
- Arnavion 5y agoThe point of giving it a GC is to let it partake in the host environment's GC instead of bundling its own. It's based around the assumption that the host can not only do a better job (eg browser JS VMs have plenty of experience with it) but also the GC can be shared in a larger context than an individual wasm program (eg all programs in the same browser tab can use the same GC). It's also needed for giving host objects to the wasm program since the host objects would be managed by the host GC.
- cogman10 5y agoThe thought is less about WASM having a GC and more about WASM being able to leverage the runtime's GC. The assumption is that WASM will run in something like a v8 where the it already has a GC for Javascript. So, rather than distributing a WASM executable with all the code needed to implement a GC, you'd have it rely on the inbuilt GC. As it stands, WASM is really only a good target for C/C++/Rust. Any other language with a more substantial runtime will end up blowing the byte budget. The question about "Should WASM do this" is really all about what WASM should/could be. Is WASM going to be a universal language target? Should it support more than low level languages? And yes, WASM exposes malloc and free.
- brabel 5y ago> And yes, WASM exposes malloc and free. No it doesn't. Unless you're referring to WASI, but WASI is not WASM, it's just a common API which modules can call when running on WASI-compliant WASM runtimes. All WASM itself has is linear memory, and that is not exposed via malloc/free, but via lower level instructions to set bytes on a page and grow when necessary (but not "free"). See the available instructions in the spec[1]. [1] https://www.w3.org/TR/wasm-core-1/#memory-instructions%E2%91%A0 https://www.w3.org/TR/wasm-core-1/#memory-instructions%E2%91...