Pointers that point from a Go object to somewhere outside the Go heap are perfectly fine. The Go runtime will not try to dereference them. unsafe.Pointer is ok, but so are concrete types, like *byte.
One caveat: the pointer must be a real pointer. Don't store a bunch of bitfields in a Go pointer type. See issue 21897 <https://github.com/golang/go/issues/21897>. On Tuesday, December 19, 2017 at 11:30:38 AM UTC-8, Xuanyi Chew wrote: > > I've partially remembered why I used unsafe.Pointer instead of uintptr. In > cases where the tensor was built from an existing memory (i.e building a > tensor with Go allocated slice backing), I wanted the slice to not be GC'd > away > > On Wednesday, 20 December 2017 00:00:10 UTC+11, Jan Mercl wrote: >> >> On Tue, Dec 19, 2017 at 1:50 PM Xuanyi Chew <che...@gmail.com> wrote: >> >> > As such I have no idea what would happen if the GC scanner hits a >> unsafe.Pointer that it cannot access. Will the pointer be marked as >> unaccessible? Does it panic with SIGBUS? >> >> I think the GC will not try to dereference a pointer that is known to >> point outside of the Go runtime heap. If I'm wrong then it will panic. I >> suggest to hide the potentially inaccessible unsafe.Pointer from being >> considered by the GC at all by making it an uintptr instead. >> >> >> -- >> >> -j >> > -- 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.