On Wednesday, June 23, 2021 at 12:00:43 PM UTC-4 jake...@gmail.com wrote:
> It does not answer your question, but possibly provides more clues: > https://play.golang.org/p/s9Xnpcx8Mys > > package main > > func main() { > var a = "b" > x := a + a // does not escape > x = a + a // does not escape > for i := 0; i < 1; i++ { > > x = a + a // a + a escapes to heap > y := a + a // does not escape > println(y) > println(x) > } > } > > > Only when a variable outside the loop is set inside the loop does it > escape. > Yes, testing is not relevant here. It is the loop make effects here. > > On Wednesday, June 23, 2021 at 12:39:17 AM UTC-4 tapi...@gmail.com wrote: > >> >> package main >> >> import "testing" >> >> var s33 = []byte{32: 'b'} >> >> var a = string(s33) >> >> func main() { >> x := a + a // a + a does not escape >> println(x) >> } >> >> func Benchmark_e_33(b *testing.B) { >> var x string >> for i := 0; i < b.N; i++ { >> x = a + a // a + a escapes to heap >> } >> println(x) >> } >> > -- 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/90ba9c4a-c96c-4d2e-b93a-e9716ad8640bn%40googlegroups.com.