pub struct Mmap { /* private fields */ }Expand description
A read-only, private memory map of an open file.
The static-delta reader maps a decompressed part or source object that was spilled to a temp file, so random access (splice offsets, bspatch source seeks) costs address space and demand-paged file cache rather than resident heap. The mapping is never written and keeps the underlying pages alive on its own, so the caller may drop the file descriptor once the map exists.
A mapping must not extend past the end of its file: reading a mapped page
with no file bytes behind it raises SIGBUS, which no safe API may
expose. Mmap::read_only therefore measures the file itself and
rejects an over-long request, and Mmap::as_slice is sound for the map’s
whole lifetime as long as nothing truncates the file underneath it. The
static-delta reader maps only anonymous temp files it alone holds, so no
other writer can shrink one.
Implementations§
Source§impl Mmap
impl Mmap
Sourcepub fn read_only(fd: impl AsFd, len: usize) -> Result<Mmap>
pub fn read_only(fd: impl AsFd, len: usize) -> Result<Mmap>
Map the first len bytes of fd read-only.
len must be nonzero and must not exceed the file’s size. A zero
length returns EINVAL from mmap, and a length past the end of the
file returns EINVAL from the size check below, so a map that would
fault on read cannot be built.