Want more features on Pastebin? Sign Up, it's FREE!
Guest

Mmap-go

By: a guest on Feb 7th, 2012  |  syntax: Go  |  size: 0.58 KB  |  views: 121  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package main
  2.  
  3. import (
  4.         "fmt"
  5.         "os"
  6.         "syscall"
  7.         "unsafe"
  8.         "github.com/edsrzf/mmap-go"
  9.         )
  10.  
  11. func main() {
  12.         n := 1000
  13.         t := int(unsafe.Sizeof(0)) * n
  14.  
  15.         map_file, _ := os.Create("/tmp/test.dat")
  16.         _, _ = map_file.Seek(int64(t - 1), 0)
  17.         map_file.Write([]byte(" "))
  18.  
  19.         /*mmap, _ := syscall.Mmap(map_file.Fd(), 0, int(t), syscall.PROT_READ | syscall.PROT_WRITE, syscall.MAP_SHARED)*/
  20.         mmap, _ := mmap.Map(map_file, syscall.PROT_NONE, mmap.RDWR)
  21.         map_array := (*[1000]int)(unsafe.Pointer(&mmap))
  22.  
  23.         for i:=0; i < n; i++ {
  24.                 map_array[i] = i*i
  25.         }
  26.  
  27.         fmt.Println(*map_array)
  28. }
clone this paste RAW Paste Data