>> Keeping a a pointer in a uintptr as a "reference" to something is safe 
iff it will never be casted back to a pointer. I think this means that the 
safe case is useless.

Storing any reference (read: address) of Go instance is unsafe because 
after when this operation ends then a stored address (as the uintptr value) 
can become not legal because any instance can be moved by GC into the other 
place (read: address).
This is a reason why recommended to perform such operation inside a sigle 
expression.

Eg.

VALID
e := unsafe.Pointer(uintptr(unsafe.Pointer(&x))

NOT VALID
addr := uintptr(unsafe.Pointer(&x)
e := unsafe.Pointer(addr)

Explained
addr := uintptr(unsafe.Pointer(&x)
// Here stored `addr` already can be non valid
e := unsafe.Pointer(addr)

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to