Giter VIP home page Giter VIP logo

emmap's Introduction

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.

emmap's People

Contributors

krestenkrab avatar lemenkov avatar stolen avatar zv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.