On unix system, we get access to syscalls that maps files or devices into memory. The main syscall is mmap, but there’s also some others syscalls in the same family to handle mapped memories like mlock, munlock, mprotect, madvise, msync.
To the rescue, I’ve released unix-memory. This provide low level access to all those syscalls. In some place, the API presented is slightly better than the raw API.
This package is supposed to be ephemeral; The goal is to fold this package to the venerable unix package when this becomes less experimental, more stable and is known to work on different unixoid platforms. If and when this happens, then this package will just provide compatibility for old versions and eventually be deprecated.
Manipulating memory is unsafe in general, so don’t expect any safety from this package, by design. Also if you don’t know what you’re doing, don’t use those APIs; It’s difficult to get right.
But it also allow interesting patterns when you cooperate with the operating system to efficiently map files, and devices as virtual memory.
A simple example opening the “/dev/zero” device first memory page, and reading 4096 bytes from it:
1 2 3 4 5 6 7 8 9 10 11
posted byon February 25, 2014.