On Fri, Feb 5, 2021 at 12:32 PM Steve Roth <st...@rothskeller.net> wrote:
> > How can I implement a writeByte function, against an unknown io.Writer > implementation, that doesn't allocate heap memory? > > As you've correctly stated, because the call to .Write() is via an interface the compiler can't tell whether any particular io.Writer will hold on to that slice. So there isn't a way to do what you want. But also, writing individual bytes to an io.Writer is likely to be a very slow thing to do so avoiding the allocation is the least of your worries. bufio.Writer has a WriteByte() method precisely to avoid the allocation problem you're encountering and it also avoids the slowness of writing individual bytes to an io.Writer https://golang.org/pkg/bufio/#Writer.WriteByte - Jesse -- 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/CAAuPoqeT%2B31oXf%2BZRZEAsQc0NQX_XUUAQ6G6kZc4HZjkOM4OXA%40mail.gmail.com.