[erlang-questions] mmap(2) to a binary?
Scott Lystig Fritchie
Fri Sep 28 18:24:03 CEST 2007
>>>>> "dt" == David Terrell <dbt@REDACTED> writes:
dt> In reference to the ongoing thread here and in the blogosphere, I
dt> had an idea for doing some arbitrary file I/O in convenient
dt> fashion. What if you could call mmap() on a file and get a binary
dt> out of it that points directly to the mapped space?
It's quite easy to do, in a naive manner. If you have a read-only
mapped region, *and* if nobody else updates the file while you've got
the region mapped, then a linked-in driver can do everything you need.
If either of those assumptions are incorrect, then a very naive driver
will violate VM internals' assumptions in a pretty spectacular way.
In the general case, I think you'd need to have two basic ops:
* map a region
* given a region, starting offset, and length, copy length
bytes into a new binary (so that its contents can't change)
In the general case, there are other things you'd also need or want,
of course: unmap a region, tie mapped regions to the process so that
the regions are unmapped if the owner process dies, ...
More information about the erlang-questions