In theory the compiler can be smart enough, if it knows that the string passed to fmt.Println is not stored and re-used someplace, but I do not believe that is currently true. It probably has at least 2 copies, one to the string in your code and a second one to make it a []byte to pass to the io.Writer. I am not sure if the later has been optimized out or not.
-Paul On Mon, Sep 19, 2016 at 4:10 PM, 'simon place' via golang-nuts < golang-nuts@googlegroups.com> wrote: > well, seems to me if you need to access a string by index, you are > assuming 1 byte per char. say ASCII, so for me you should be using []byte > to store it, then 'cast' to see it as a string. > > https://play.golang.org/p/2NMye8gnzg > > surely this doesn't do any copying? > > -- > 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. > -- 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.