I would start with the naive implementation first, and only make it fancier (and more complicated) if that turns out not to be fast enough. Go's GC is pretty good already and getting better.
You must not change the data in the returned slice after returning it, unless you somehow know that the caller is done with the slice by then and even then it would be brittle.
Don't implement Read with semantics other than those defined in the io module (returning an error if the buffer is too small); that's asking for trouble. It would be fine to implement io.WriterTo though, and the caller could pass you a bytes.Buffer to write into.
I think this seems like a good use case for sync.Pool, but you should benchmark and profile to be sure.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.