UnixMmap.jl Documentation

Installation and loading is as easy as:

pkg> add UnixMmap

julia> using UnixMmap

A file can be memory mapped (read-only by default) by calling UnixMmap.mmap with a filename and the Array type to be applied (and optionally with dimensions to give a shape):

julia> UnixMmap.mmap("arbitrary.dat", Vector{Float64})
192-element Vector{Float64}:
 0.0
 0.0
 ⋮
 0.0
 0.0

julia> UnixMmap.mmap("arbitrary.dat", Matrix{Float64}, (64, 3))
64×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 ⋮
 0.0  0.0  0.0
 0.0  0.0  0.0

while an anonymous memory map can be created by instead specifying the Array type and dimensions:

julia> UnixMmap.mmap(Matrix{Float64}, (128, 3))
128×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 ⋮
 0.0  0.0  0.0
 0.0  0.0  0.0

The notable features that UnixMmap.jl provides over the standard library's Mmap module is the ability to set Unix-specific flags during mapping. For example, on Linux the MAP_POPULATE flag can be used to advise the kernel to prefault all mapped pages into active memory.

julia> UnixMmap.mmap("arbitrary.dat", Matrix{Float64}, (64, 3);
                     flags = UnixMmap.MAP_SHARED | UnixMmap.MAP_POPULATE)
64×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 ⋮
 0.0  0.0  0.0
 0.0  0.0  0.0

UnixMmap.jl provides OS-specific flags for several Unixes; see the Constants section for more details.

The package also exposes the UnixMmap.madvise!, UnixMmap.msync!, and UnixMmap.mincore functions which correspond closely to the underlying system calls.

Library API Reference