mmap

mmap() fds into buffers

  • mmap

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mmap
2752.0.210 years ago11 years agoMinified + gzip package size for mmap in KB

Readme

mmap
mmap(2) bindings for node.js that work in 0.10

Installing

npm test
npm install -g

Usage

mmap = require("mmap")
buffer = mmap(n_bytes, protection, flags, fd, offset)
<td><i>n_bytes</i></td>
<td>The number of bytes to map into memory.</td>
<td><i>protection</i></td>
<td>Memory protection: either <b>mmap.PROT_NONE</b> or a bitwise OR of <b>mmap.PROT_READ</b>, <b>mmap.PROT_WRITE</b> and <b>mmap.PROT_EXEC</b>.</td>
<td><i>flags</i></td>
<td>Flags: either <b>mmap.MAP_SHARED</b> or <b>mmap.MAP_PRIVATE</b>.</td>
<td><i>fd</i></td>
<td>File descriptor. You can also use a file name (string). When you do this, <b>mmap()</b> tries to do the right thing by creating or growing the file to <i>n_bytes</i> if necessary.</td>
<td><i>offset</i></td>
<td>File offset. Must be either zero or a multiple of <b>mmap.PAGESIZE</b>.</td>

While a finaliser is installed to automatically unmap buffer, you can force it to unmap immediately with:
buffer.unmap()
You can also msync() by calling: buffer.sync([offset, [length, [flags]]]) method:
<td><i>offset</i></td>
<td>The start address to sync. This argument optional, the default is 0.</td>
<td><i>length</i></td>
<td>The number of bytes to sync. This argument optional, the default is the entire buffer.</td>
<td><i>flags</i></td>
<td>Flags: either <b>mmap.MS_SYNC</b> or <b>mmap.MS_ASYNC</b> optionally bitwise OR with <b>mmap.MS_INVALIDATE</b>. This argument is optional, the default is <b>mmap.MS_SYNC</b>.</td>

For compatibility, mmap.map() is an alias for mmap()

See Also

  • POSIX 1003.1 mmap and msync
  • The example/ directory contains some sample uses of the mmap module
  • bnoordhuis/node-mmap, the original node-mmap, on which this is based.