github.com/outcaste-io/ristretto@v0.2.3/z/mmap.go (about)

     1  /*
     2   * Copyright 2019 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package z
    18  
    19  import (
    20  	"os"
    21  )
    22  
    23  // Mmap uses the mmap system call to memory-map a file. If writable is true,
    24  // memory protection of the pages is set so that they may be written to as well.
    25  func Mmap(fd *os.File, writable bool, size int64) ([]byte, error) {
    26  	return mmap(fd, writable, size)
    27  }
    28  
    29  // Munmap unmaps a previously mapped slice.
    30  func Munmap(b []byte) error {
    31  	return munmap(b)
    32  }
    33  
    34  // Madvise uses the madvise system call to give advise about the use of memory
    35  // when using a slice that is memory-mapped to a file. Set the readahead flag to
    36  // false if page references are expected in random order.
    37  func Madvise(b []byte, readahead bool) error {
    38  	return madvise(b, readahead)
    39  }
    40  
    41  // Msync would call sync on the mmapped data.
    42  func Msync(b []byte) error {
    43  	return msync(b)
    44  }