On Mon, May 27, 2019 at 2:18 AM Sergey Kamardin <gob...@gmail.com> wrote: > > On Sun, 05/26/19, May 26, 2019 at 07:59:07PM -0400, Ian Lance Taylor wrote: > > This is not valid. The rule is that SliceHeader is only valid when > > inspecting an actual slice header. You have to write > > > > h.Data = uintptr(unsafe.Pointer(&b)) > > h.Len = len(b) > > h.Cap = len(b) > > > > I assume this is reduced greatly from the real code, as you could also > > just write > > > > bts = b[:] > > Does this mean that it is not possible to get rid of heap allocation for > passing slice of bytes to some method interface like io.Reader.Read()? > > Both code examples above are leading b to escape to the heap when > passing to the interface method.
Yes, with the current implementation, as far as I know, there is no way to avoid the slice escaping to the heap when calling Read through an interface value. With the current implementation, any successful attempt to avoid the slice escaping to the heap can cause the garbage collector to fail. 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWZcHHjxaETd1i_%2BQPegO5P3ZEoQ16ehP_30ryDp_4O6w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.