Skip to content

Commit 4cb7be9

Browse files
committed
Add example usages in documentation
1 parent 1bd99b5 commit 4cb7be9

File tree

3 files changed

+94
-15
lines changed

3 files changed

+94
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "UnixMmap"
22
uuid = "674b2976-56af-439b-a2b1-837be4a3d087"
33
authors = ["Justin Willmert <justin@willmert.me> and contributors"]
4-
version = "0.1.1"
4+
version = "1.0.0"
55

66
[deps]
77
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,42 @@ exposing the Unix memory-mapping interface.
99

1010
### Installation and usage
1111

12-
This library is **not** registered in Julia's [General registry][General.jl],
13-
so the package must be installed either by cloning it directly:
12+
Installation and loading is as easy as:
13+
```julia
14+
pkg> add UnixMmap
1415

15-
```
16-
(@v1.6) pkg> add https://github.com/jmert/UnixMmap.jl
17-
```
18-
19-
or by making use of my [personal registry][Registry.jl]:
20-
21-
```
22-
(@v1.6) pkg> registry add https://github.com/jmert/Registry.jl
23-
(@v1.6) pkg> add UnixMmap
16+
julia> using UnixMmap
2417
```
2518

26-
After installing, just load like any other Julia package:
27-
19+
A file can be memory mapped (read-only by default) by giving the filename and the `Array`
20+
type (optionally with dimensions to give a shape):
21+
```julia
22+
julia> UnixMmap.mmap("arbitrary.dat", Array{Float64})
23+
192-element Vector{Float64}:
24+
0.0
25+
0.0
26+
27+
0.0
28+
0.0
29+
30+
julia> UnixMmap.mmap("arbitrary.dat", Array{Float64}, (64, 3))
31+
64×3 Matrix{Float64}:
32+
0.0 0.0 0.0
33+
0.0 0.0 0.0
34+
35+
0.0 0.0 0.0
36+
0.0 0.0 0.0
2837
```
29-
julia> using UnixMmap
38+
while an anonymous memory map can be created by instead specifying the `Array` type and
39+
dimensions:
40+
```julia
41+
julia> UnixMmap.mmap(Array{Float64}, (128, 3))
42+
128×3 Matrix{Float64}:
43+
0.0 0.0 0.0
44+
0.0 0.0 0.0
45+
46+
0.0 0.0 0.0
47+
0.0 0.0 0.0
3048
```
3149

3250
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg

docs/src/index.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# UnixMmap.jl Documentation
22

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+
364
## Library API Reference
465
```@contents
566
Pages = [

0 commit comments

Comments
 (0)