package main
import "fmt"
import "unsafe"
import "runtime"
func f() **int {
for false{} // avoid f being inlined.
s := make([]byte, unsafe.Sizeof((*int)(nil))) // enough memory to hold
a pointer
pp := (**int)(unsafe.Pointer(&s[0]))
x := 123
*pp = &x
return pp
}
var a []int
func main() {
p := f()
runtime.GC()
// Is the memory allocated for x in f
// guaranteed to be reachable at this moment?
a = make([]int, 10)
fmt.Println(**p, a)
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.