Skip to content

Commit 3ccb9e3

Browse files
committed
Improve the function docs.
1 parent ac65dc8 commit 3ccb9e3

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

src/mmap.jl

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,7 @@ function mmap(::Type{Array{T}}, dims::NTuple{N,Integer};
294294
flags::Union{MmapFlags,Nothing} = nothing
295295
) where {T, N}
296296
prot = prot === nothing ? PROT_READ | PROT_WRITE : prot
297-
if flags === nothing
298-
flags = MAP_SHARED | MAP_ANONYMOUS
299-
else
300-
flags |= MAP_ANONYMOUS
301-
end
297+
flags = MAP_ANONYMOUS | (flags === nothing ? MAP_SHARED : flags)
302298
return mmap(Anonymous(), Array{T}, dims;
303299
offset = Int64(0), prot = prot, flags = flags, grow = false)
304300
end
@@ -311,33 +307,43 @@ function mmap(::Type{Array{T}}, len::Integer;
311307
end
312308

313309
"""
314-
mmap(io::IO, ::Type{Array{T,N}}, dims::NTuple{N,Integer}; kws...) where {T,N}
315-
mmap(io::IO, ::Type{Vector{T}}, len::Integer; kws...) where {T}
316-
mmap(io::IO, ::Type{Vector{T}}; kws...) where {T}
310+
mmap(file::Union{IO,AbstractString}[, ::Type{Array{T}}, dims]; kws...)
311+
mmap(::Type{Array{T}}, dims; kws...)
317312
313+
Memory maps an `Array` from a file `file` of size `dims` (either a scalar `Integer` or
314+
a tuple of dimension lengths), or creates an anonymous mapping not backed by a file if
315+
no file is given.
318316
319-
mmap(filename::AbstractString, ::Type{Array{T,N}}, dims::NTuple{N,Integer}; kws...) where {T,N}
320-
mmap(filename::AbstractString, ::Type{Vector{T}}, len::Integer; kws...) where {T}
321-
mmap(filename::AbstractString, ::Type{Vector{T}}; kws...) where {T}
317+
If not specified, the array type defaults to `Array{UInt8}`, and `dim` defaults to a
318+
vector with length equal to the number of elements remaining in the file (accounting for
319+
a non-zero position in the file stream `io`).
322320
321+
# Extended help
323322
324-
mmap(::Type{Array{T,N}}, dims::NTuple{N,Integer}; kws...) where {T,N}
325-
mmap(::Type{Vector{T}}, dims::Integer; kws...) where {T}
323+
This function provides a relatively simple wrapper around the underlying `mmap` system
324+
call. In particular, it is the user's responsibility to ensure the combination(s) of
325+
stream state (e.g. read/write or read-only, file length), protection flags, and memory map
326+
flags must form a valid `mmap` request, as they are not validated here.
326327
327-
# Extended help
328+
See your system `mmap` man page for details on the behaviors of each flag.
328329
329330
## Keywords
330331
331-
* `flags`
332-
* `prot`
333-
* `offset`
334-
* `grow`
332+
The following keywords are available:
333+
334+
* `flags::MmapFlags` — any of the `MAP_*` system-specific constants. For files, this
335+
defaults to `MAP_SHARED`, and anonymous mappings default to `MAP_SHARED | MAP_ANONYMOUS`.
335336
336-
## Low-level Interfaces
337+
* `prot::MmapProtection` — any of the `PROT_*` flags. The default is `PROT_READ |
338+
PROT_WRITE` for all anonymous maps and memory maps of non-existent files (in which case
339+
the file will be created). If the file already exists, it is opened read-only and the
340+
default is `PROT_READ` only.
337341
338-
mmap(::Type{Array{T,N}}, dims::NTuple{N,Integer},
339-
prot::MmapProtection, flags::MmapFlags, fd::RawFD, offset::Integer) where {N,T}
342+
* `offset::Integer` — offset _in bytes_ from the beginning of the file, defaulting to the current
343+
stream position. This keyword is not valid for anonymous maps.
340344
345+
* `grow::Bool` — Whether to grow a file to accomodate the memory map, if the file is
346+
writable. Defaults to `true`. This keyword is not valid for anonymous maps.
341347
"""
342348
function mmap end
343349

@@ -357,8 +363,10 @@ pages of the memory-mapped `array` are resident in RAM. Pages corresponding to `
357363
values will cause a fault if referenced.
358364
359365
!!! note
360-
The return array will not map to `PAGESIZE` chunks of `array` if the `mmap` offset
361-
was not a multiple of `PAGESIZE`.
366+
Memory maps are always page-aligned, so an offset which is not a multiple of `PAGESIZE`
367+
will result in a return array where the first element does _not_ correspond to the
368+
first `PAGESIZE ÷ sizeof(eltype(array))` elements of `array` — i.e. the first page
369+
may cover memory addresses before the first element of `array`.
362370
"""
363371
function mincore(array::Array)
364372
ptr, _, len = pagepointer(array)

0 commit comments

Comments
 (0)