Description
Motivation
Currently, the [MemoryView::read
] function is 1-copy. This is obviously required on some platforms (like Web), but it would be nice if there was no enforced copy on Native when the instance memory is owned by our process.
Proposed solution
Change [MemoryView::read
], or add a new alternative, which returns a Cow<'a, [u8]>
which performs the copy on platforms which require it, and doesn't on the platforms which don't.
Unfortunately due to the write
method taking an immutable reference, having this Cow<'a, [u8]>
would break the concurrency guarantees provided. Ultimately I'm unsure why [MemoryView::write
] doesn't take a mutable reference.
Alternatives
Currently (to my knowledge) there is no way to exploit 0-copy reads from host memory. Therefore the alternative is lost performance.