Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Erlang Memory Map

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 c_src
Octocat-spinner-32 doc
Octocat-spinner-32 ebin
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 rebar
Octocat-spinner-32 rebar.config
README.md

Erlang MMAP emmap

This Erlang library provides a wrapper that allows you to memory map files into the Erlang memory space.

Basic Usage

The basic usage is

{ok, Mem} = emmap:open("filename", [read, shared, direct]),
{ok, Binary} = file:pread(Mem, 100, 40),
...
ok = file:close(Mem).

The open options is a list containing zero or more of these:

  • read, write: Open for reading and/or writing (you can specify both).
  • private, shared: The file is opened with copy-on-write semantics, or sharing memory with the underlying file.
  • direct: read/pread operations do not copy memory, but rather use "resource binaries" that can change content if the underlying data is changed. This is the most performant, but also has other implications.
  • lock, nolock do (or do not) use a semaphore to control state changes internally in the NIF library.

From this point, Mem can be used with the file operations

  • {ok, Binary} = file:pread(Mem, Position, Length) read Length bytes at Position in the file.
  • ok = file:pwrite(Mem, Position, Binary) writes to the given position.
  • {ok, Binary} = file:read(Mem, Length) read 1..Length bytes from current position, or return eof if pointer is at end of file.
  • {ok, Pos} = file:position(Mem, Where) see file:position/2 documentation.
  • ok = file:close(Mem)

Notes

Using the option direct has the effect that the mmap file is not closed until all references to binaries coming out of read/pread have been garbage collected. This is a consequence of that such binaries are referring directly to the mmap'ed memory.

Something went wrong with that request. Please try again.