[]byte is mutable in Go, but string is readonly, so []byte(string) in Go is 
actually allocate&memcopy, and this operation is costly.
Sometimes, we need a readonly []byte parameter but we have string only, and 
we have no choice but allocate&memcopy to make a new []byte variable from 
string.
Eg: net.Send([]byte("ping")) is costly, but net.Send(readonly 
[]byte("ping")) can be cheaply.

-- 
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/415ad061-f7bd-4f10-ac93-dca404b5cedc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to