[erlang-questions] mmap(2) to a binary?
Fri Sep 28 17:53:34 CEST 2007
On 9/27/07, David Terrell <dbt@REDACTED> wrote:
> In reference to the ongoing thread here and in the blogosphere,
> I had an idea for doing some arbitrary file I/O in convenient
> fashion. What if you could call mmap() on a file and get a binary
> out of it that points directly to the mapped space?
> would someone more familiar with the internals of the beam machine
> tell me if that's possible or not? I don't know if you'd have to
> hold open some sort of port that kept it alive and kill it when
> it died, or if it's completely impossible, but it seems like a
> really efficient way to sidestep the drama of read(2) and friends.
I emailed this same suggestion to Tim Bray a few days ago. To gain the
efficiency of mmap, in your driver C code you'd need to be able to allocate
a binary whose buffer met mmap's alignment requirement, which is that the
address being mapped to be page-aligned. Without page alignment, you'd be
forced to mmap and copy, which would defeat the purpose of using mmap.
Unfortunately, unless I'm missing something this alignment is pretty much
impossible to guarantee without adding a special-purpose binary allocator to
force such alignment.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions