On Thu, Mar 1, 2018 at 9:04 AM, <d...@veryhaha.com> wrote: > > Is the KeepAlive call in the following example essential? and sufficient? > > func ByteSlice2String(bs []byte) (str string) { > sliceHdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) > strHdr := (*reflect.StringHeader)(unsafe.Pointer(&str)) > strHdr.Len = sliceHdr.Len > strHdr.Data = sliceHdr.Data > runtime.KeepAlive(&bs) // is this line essential? is it sufficient? > return > }
Yes, I think it is both required and sufficient. Ian -- 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.