Open axic opened 5 years ago
Curious, was there a reason for not allowing Ewasm modules to export/import a memory instance between each other? Or modules importing the same memory instance?
Someone may complain about memory copying overhead dominating runtime for some use-cases.
This is related to #17 and #188 / #181 to some extent.
If doing runtime linking, where libraries are spawned as separate instances with their own memory, there is a problem passing data between these instances. The "Wasm threads" proposal (here) contains support for shared memory segments, but finalisation of that is still quite far out in the future.
A simplistic API and approach is presented here, modelled after POSIX's
shm
subsystem.shmemCreate(id: u64, size: u32, ptr: u32, len: u32)
- creates a shared memory buffer withsize
and loads the initial value fromptr ... ptr+len
(len
can be zero and in that case noptr
can also be "invalid")shmemAttach(id: u64, ptr: u32, len: u32)
- attaches a shared memory buffer and loads the current value to the memory area pointed byptr
shmemDetach(ptr: u32)
- detaches the local memory area from any updatesshmemSize(id: u64)
- returns the size of the shared memorySince no parallel execution exists in "ewasm", whenever a linked module is called, the caller has stopped executing. When a callee is finished, the shared memory areas used are updated prior to returning execution to the caller.
As an example: