Hi, folks, I could use some assistance getting rid of some unnecessary heap allocations. I have code that needs to write individual bytes to an io.Writer. (The Writer implementation given to my code is probably buffered, but my code shouldn't rely on a particular concrete type.) The relevant part of code looks like this:
func writeByte(b byte) { var buf [1]byte buf[0] = b _, err = w.Write(buf[:]) } Unfortunately, I find that every call of this function allocates a byte on the heap. The compiler's escape analysis can't be sure that the Write method doesn't keep a copy of the pointer it's given, so "buf" escapes to the heap. How can I implement a writeByte function, against an unknown io.Writer implementation, that doesn't allocate heap memory? Thanks, Steve -- 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/CAAnpqKHDg2tmR%2Bupd5PhWUArzS-f6B6BzoSzGWYz%3DwFJJLsmQQ%40mail.gmail.com.