mmap.go 820 B

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