[erlang-questions] mmap file to binary

Mikael Pettersson <>
Fri Apr 9 07:18:11 CEST 2010

Max Lapshin writes:
 > I've thought a lot about mmap usage in erlang and haven't found any
 > good solution.
 > Main idea is that when file is mmaped to address space, it is possible
 > to take chunks from it without any copying:
 > {ok, Bin} = file:mmap(File),
 > <<_:LargeOffset/binary, InsideBinary:Size/binary, _/binary>> = Bin,
 > But what to do, when file is closed and all binaries, that referred
 > into this address space becomes unusable?

If we're talking Unix-like OSs, then closing a file descriptor
does not nuke any mappings made on it. So this is a non-problem.

The only problem I see is the munmap rather than free when the
off-heap wrapper binary dies, as I wrote before. But that should
be fixable with a flag in the off-heap binary.

More information about the erlang-questions mailing list