|
1 | 1 | # UnixMmap.jl Documentation |
2 | 2 |
|
| 3 | +Installation and loading is as easy as: |
| 4 | +```julia-repl |
| 5 | +pkg> add UnixMmap |
| 6 | +
|
| 7 | +julia> using UnixMmap |
| 8 | +``` |
| 9 | + |
| 10 | +A file can be memory mapped (read-only by default) by calling [`UnixMmap.mmap`](@ref) |
| 11 | +with a filename and the `Array` type to be applied (and optionally with dimensions to give a |
| 12 | +shape): |
| 13 | +```julia-repl |
| 14 | +julia> UnixMmap.mmap("arbitrary.dat", Array{Float64}) |
| 15 | +192-element Vector{Float64}: |
| 16 | + 0.0 |
| 17 | + 0.0 |
| 18 | + ⋮ |
| 19 | + 0.0 |
| 20 | + 0.0 |
| 21 | +
|
| 22 | +julia> UnixMmap.mmap("arbitrary.dat", Array{Float64}, (64, 3)) |
| 23 | +64×3 Matrix{Float64}: |
| 24 | + 0.0 0.0 0.0 |
| 25 | + 0.0 0.0 0.0 |
| 26 | + ⋮ |
| 27 | + 0.0 0.0 0.0 |
| 28 | + 0.0 0.0 0.0 |
| 29 | +``` |
| 30 | +while an anonymous memory map can be created by instead specifying the `Array` type and |
| 31 | +dimensions: |
| 32 | +```julia-repl |
| 33 | +julia> UnixMmap.mmap(Array{Float64}, (128, 3)) |
| 34 | +128×3 Matrix{Float64}: |
| 35 | + 0.0 0.0 0.0 |
| 36 | + 0.0 0.0 0.0 |
| 37 | + ⋮ |
| 38 | + 0.0 0.0 0.0 |
| 39 | + 0.0 0.0 0.0 |
| 40 | +``` |
| 41 | + |
| 42 | +The notable features that UnixMmap.jl provides over the standard library's Mmap module |
| 43 | +is the ability to set Unix-specific flags during mapping. |
| 44 | +For example, on Linux the `MAP_POPULATE` flag can be used to advise the kernel to |
| 45 | +prefault all mapped pages into active memory. |
| 46 | +```julia-repl |
| 47 | +julia> UnixMmap.mmap("arbitrary.dat", Array{Float64}, (64, 3); |
| 48 | + flags = UnixMmap.MAP_SHARED | UnixMmap.MAP_POPULATE) |
| 49 | +64×3 Matrix{Float64}: |
| 50 | + 0.0 0.0 0.0 |
| 51 | + 0.0 0.0 0.0 |
| 52 | + ⋮ |
| 53 | + 0.0 0.0 0.0 |
| 54 | + 0.0 0.0 0.0 |
| 55 | +``` |
| 56 | + |
| 57 | +UnixMmap.jl provides OS-specific flags for several Unixes; see the |
| 58 | +[Constants](@ref Constants-—-Linux) section for more details. |
| 59 | + |
| 60 | +The package also exposes the [`UnixMmap.madvise!`](@ref), [`UnixMmap.msync!`](@ref), and |
| 61 | +[`UnixMmap.mincore`](@ref) functions which correspond closely to the underlying system |
| 62 | +calls. |
| 63 | + |
3 | 64 | ## Library API Reference |
4 | 65 | ```@contents |
5 | 66 | Pages = [ |
|
0 commit comments