在Golang中从[] byte和字符串转换的技术问题

Is it true that converting from string to []byte allocates new memory? Also, does converting from []byte to string allocates new memory?

 s := "a very long string"
 b := []byte(s) // does this doubled the memory requirement?

 b := []byte{1,2,3,4,5, ...very long bytes..}
 s := string(b) // does this doubled the memory requirement?

Yes in both cases.

String types are immutable. Therefore converting them to a mutable slice type will allocate a new slice. See also http://blog.golang.org/go-slices-usage-and-internals

The same with the inverse. Otherwise mutating the slice would change the string, which would contradict the spec.