SHARE
TWEET

Mmap-go

a guest Feb 7th, 2012 141 Never
  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. }
RAW Paste Data
Top