[erlang-questions] mmap file to binary

Mikael Pettersson <>
Sat Apr 3 14:23:28 CEST 2010


On Sat, 3 Apr 2010 10:57:49 +0400, Max Lapshin wrote:
> I want to add mmap reading of files, because it have shown better
> results on server, written in C, than plain reading.
> 
> There was discussion in 2007
> http://www.erlang.org/pipermail/erlang-questions/2007-September/029560.html
> and some blog posts:
> http://steve.vinoski.net/blog/2007/09/29/more-file-processing-with-erlang/
> 
> In the latter, author say:
> > because of mmap's alignment restrictions combined with the way the
> > Erlang runtime allocate binaries, I was forced to copy the data into the
> > binary,
> 
> Have anything changed?
> 
> It seems to be possible to create binary from existing area in memory,
> which is controlled by C code, not by erlang.
> I'm ready to test with linked-in driver, but maybe, there are some
> other ideas or implementations?

It looks to me like an off-heap ProcBin should work. They separate
the object header (required by Erlang) from the actual data bytes,
so the data bytes should be able to reside in an mmap:ed blob.

The runtime system may need to be tweaked to munmap() the data rather
than free() it when the binary dies, but that's a minor issue.


More information about the erlang-questions mailing list