On Tue, Nov 24, 2009 at 10:02, Mike Beller <
belle...@gmail.com> wrote:
> Is there any particular reason that mmap is not supported?
>
> mmap is a very powerful capability, especially in Linux, for example,
> where it is used for super-low-overhead file I/O, for sharing memory
> between applications, and ultimately, it's the underlying memory
> allocator in Linux (brk is built on top of anonymous mmap). I would
> say a language which calls itself a system programming language will
> need some support for mmap.
>
> If there is no language-specific reason not to do it, perhaps you
> could hint at how I could go about building it, or whether anyone else
> already is.
Go already calls mmap to get memory. The first reason there
is no interface for mmapping files is that we haven't needed it yet,
but it's also not clear how to make it fit well with the rest of the system.
The basic mmap call would have to return a []byte, but most
programs that mmap a file want to interpret it as native data structures.
Preparing that file implies precise knowledge of the memory layout
of specific structures, which Go tries to hide for portability reasons,
and the conversion itself would require importing "unsafe",
which Go tries to avoid as much as possible. (That said, I certainly
appreciate that this is an important use case.) Even once the
conversion is done, it's not clear how mmap interacts with the garbage
collector. You wouldn't want to depend on storing Go pointers
in the mmap'ed region and hope the garbage collector doesn't
collect those objects. A thornier problem is deciding when it is
safe to unmap the file. The easy answer is never; more precise
answers will require even more chumminess with the garbage
collector.
Until these questions are answered, the simplest thing to do is
just call it directly using the syscall package and take responsibility
for the safety or lack thereof. The toy Native Client code has
a use of mmap in that context, which you could look at for inspiration:
http://golang.org/src/pkg/exp/nacl/av/av.go?h=SYS_MMAP#L261
On Tue, Nov 24, 2009 at 10:34, Uriel <
ur...@berlinblue.org> wrote:
> We really got to have mmap; any system should implement two, and only
> two, interfaces: mmap and ioctl.
>
> We should do away with all that annoying and tedious open/read/write
> silliness, those crazy Unix people had no clue what they were doing.
Writing these rants is probably not a productive use of your time,
and reading them is certainly a waste of our time. People in
different situations may make different design decisions, and
that's entirely reasonable. It's just not interesting to watch you
jump all over people because they have different problems than
you do. (You'll probably be disappointed to learn that mmap is
a fundamental part of the implementation of
http://9fans.net/archive/.)
Please take your non-constructive comments elsewhere. Thanks.
Russ