Skip to content

0-copy memory reads #4362

Open
Open
@Joeoc2001

Description

@Joeoc2001

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions