amuz.es/src/go/misc@v1.0.1/strutil/trick.go (about) 1 package strutil 2 3 import ( 4 "unsafe" 5 ) 6 7 // B2S converts byte slice to a string without memory allocation. 8 // See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ . 9 // 10 // Note it may break if string and/or slice header will change 11 // in the future go versions. 12 func B2S(b []byte) string { 13 return *(*string)(unsafe.Pointer(&b)) 14 }