<div><span class="gmail_quote">On 9/27/07, <b class="gmail_sendername">David Terrell</b> <<a href="mailto:dbt@meat.net">dbt@meat.net</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
In reference to the ongoing thread here and in the blogosphere,<br>I had an idea for doing some arbitrary file I/O in convenient<br>fashion.  What if you could call mmap() on a file and get a binary<br>out of it that points directly to the mapped space?
<br><br>would someone more familiar with the internals of the beam machine<br>tell me if that's possible or not?  I don't know if you'd have to<br>hold open some sort of port that kept it alive and kill it when
<br>it died, or if it's completely impossible, but it seems like a<br>really efficient way to sidestep the drama of read(2) and friends.<br></blockquote></div><br><div>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.
</div><div><br class="webkit-block-placeholder"></div><div>--steve</div>