mmap.go raw
1 /*
2 * SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6 package z
7
8 import (
9 "os"
10 )
11
12 // Mmap uses the mmap system call to memory-map a file. If writable is true,
13 // memory protection of the pages is set so that they may be written to as well.
14 func Mmap(fd *os.File, writable bool, size int64) ([]byte, error) {
15 return mmap(fd, writable, size)
16 }
17
18 // Munmap unmaps a previously mapped slice.
19 func Munmap(b []byte) error {
20 return munmap(b)
21 }
22
23 // Madvise uses the madvise system call to give advise about the use of memory
24 // when using a slice that is memory-mapped to a file. Set the readahead flag to
25 // false if page references are expected in random order.
26 func Madvise(b []byte, readahead bool) error {
27 return madvise(b, readahead)
28 }
29
30 // Msync would call sync on the mmapped data.
31 func Msync(b []byte) error {
32 return msync(b)
33 }
34