Description
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.