Skip to content

x/exp/mmap: should offer access to the mapped byte slice #20642

Open
@AndreKR

Description

@AndreKR

Currently the only way the mapped data is accessible is through the ReadAt(p []byte, off int64) method, which copies from r.data (the mapped area) to p.

I realize that this was probably a deliberate decision, because if it were possible to create further references to the underlying (mapped) array of r.data and those references were accessed after the ReaderAt's Close() method was called, the application would crash.

However, one of the reasons to use mmap is usually performance. In my application I am just copying big chunks of data out of an mmapped area into a pipe. To be honest I have not quantified the impact, but I can imagine that if I could avoid the second copying I could increase the throughput/reduce the CPU load.

Maybe the issue of unsafeness can be addressed by allowing access through a Method named something like UnsafeRawAccess() or something?

The reason why I don't just implement the whole mmapping myself is that the package still offers some value in abstracting the mmap system calls for the different platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions