1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main

import (
"fmt"
"log"
"syscall"
"time"
"unsafe"
)

type Data struct {
Name string
Age int
}

func main() {
go put()
go get()
select {}
}

func get() {

file, _ := syscall.UTF16PtrFromString("ShareMemory")
size := 100000 // I’ve tried unsafe.Sizeof(MumbleData{}) but that didn’t work.
handle, err := syscall.CreateFileMapping(0, nil, syscall.PAGE_READWRITE, 0, uint32(size), file)
if err != nil {
log.Fatal(err)
}
defer syscall.CloseHandle(handle)

addr, err := syscall.MapViewOfFile(handle, syscall.FILE_MAP_WRITE, 0, 0, 0)
if err != nil {
log.Fatal(err)
}

for i := 0; i < 100; i++ {
fmt.Println(*(*Data)(unsafe.Pointer(uintptr(addr))))
time.Sleep(time.Second)
}
}

func put() {

file, _ := syscall.UTF16PtrFromString("ShareMemory")
size := 100000 // I’ve tried unsafe.Sizeof(MumbleData{}) but that didn’t work.
handle, err := syscall.CreateFileMapping(0, nil, syscall.PAGE_READWRITE, 0, uint32(size), file)
if err != nil {
log.Fatal(err)
}
defer syscall.CloseHandle(handle)

addr, err := syscall.MapViewOfFile(handle, syscall.FILE_MAP_WRITE, 0, 0, 0)
if err != nil {
log.Fatal(err)
}

for i := 0; i < 100; i++ {
*(*Data)(unsafe.Pointer(uintptr(addr))) = Data{Name:"xmge",Age:i}
time.Sleep(time.Second *2)
}
}