Is there a way to instantiate two Wasm modules, a
and b
such that a
can call functions from b
and also access the distinct memory from b
? For example, let's say that a
gets memory by calling an implementation of malloc
in b
that is exposed to a
. This way, all useful memory comes from b
. If so, how can it be done?
More specifically, can this be done without additional overhead, and without interacting with JavaScript in-between these operations (except for the initialization step when instantiating the modules and setting imports/exports)? What are the performance characteristics of this sort of indirection and memory access, or is there no issue at all? In this case, I want to micro-optimize.
(I've read several pieces of documentation, but I can't find a clear answer. I think that in future versions of Wasm, there are plans for standardized dynamic linking that would help, but we're not there yet.)