github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/lib/mmap/mmap.go (about)

     1  package mmap
     2  
     3  import "os"
     4  
     5  // PageSize is the minimum allocation size.  Allocations will use at
     6  // least this size and are likely to be multiplied up to a multiple of
     7  // this size.
     8  var PageSize = os.Getpagesize()
     9  
    10  // MustAlloc allocates size bytes and returns a slice containing them.  If
    11  // the allocation fails it will panic.  This is best used for
    12  // allocations which are a multiple of the PageSize.
    13  func MustAlloc(size int) []byte {
    14  	mem, err := Alloc(size)
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  	return mem
    19  }
    20  
    21  // MustFree frees buffers allocated by Alloc.  Note it should be passed
    22  // the same slice (not a derived slice) that Alloc returned.  If the
    23  // free fails it will panic.
    24  func MustFree(mem []byte) {
    25  	err := Free(mem)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  }