uintptr, , , .
,
package main
import (
"fmt"
"time"
"unsafe"
)
type T struct{ a, b int }
func main() {
memmap := make(map[uintptr]int64)
pT := new(T)
memmap[uintptr(unsafe.Pointer(pT))] = time.Nanoseconds()
pT.a = 1
pT.b = 2
fmt.Printf("%d %d %p %T\n", pT.a, pT.b, pT, pT)
pI := new(int)
memmap[uintptr(unsafe.Pointer(pI))] = time.Nanoseconds()
*pI = 42
fmt.Printf("%d %p %T\n", *pI, pI, pI)
fmt.Printf("\n%T\n", memmap)
for k, v := range memmap {
fmt.Printf("%x: %d\n", k, v)
}
}
:
1 2 0xf8400001f8 *main.T
42 0xf8400001f0 *int
map[uintptr] int64
f8400001f0: 1306837191421330000
f8400001f8: 1306837191421293000