mmap.go 892 B

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