On Sunday, May 23, 2021 at 5:04:37 AM UTC-4 axel.wa...@googlemail.com wrote:
> On Sun, May 23, 2021 at 11:02 AM tapi...@gmail.com <tapi...@gmail.com> > wrote: > >> And how to interpret the conflicting messages for the following program? >> > > In one case, `g` is inlined, which is sufficient to prove that its return > does not escape. But if you only analyse `g` as-is, you must assume that > the return has to escape, as you don't know what the caller would do with > is. > I also think so. It looks the message "make([]T, N) escapes to heap" in g means "make([]T, N)" will escape to heap if g is not inlined. > > >> >> package main >> >> type T int >> >> const N = 1<<12 >> var i = N - 1 >> >> func main() { >> var r = make([]T, N) // make([]T, N) does not escape >> println(r[i]) >> >> var r1 = g() // make([]T, N) does not escape >> println(r1[i]) >> >> } >> >> func g() []T { >> var ts = make([]T, N) // make([]T, N) escapes to heap >> return ts >> } >> >> On Sunday, May 23, 2021 at 4:51:30 AM UTC-4 tapi...@gmail.com wrote: >> >>> In the following code, "make([]T, n)" is reported as escaped. >>> But does it really always escape at run time? >>> Does the report just mean "make([]T, n) possibly escapes to heap"? >>> >>> package main >>> >>> type T int >>> >>> const K = 1<<13 >>> const N = 1<<12 >>> var n = N >>> var i = n-1 >>> >>> func main() { >>> var r = make([]T, N) // make([]T, N) does not escape >>> println(r[i]) >>> >>> var r2 = make([]T, n) // make([]T, n) escapes to heap >>> println(r2[i]) >>> >>> var r3 = make([]T, K) // make([]T, K) escapes to heap >>> println(r3[i]) >>> } >>> >> -- >> > 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...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0f563565-42a0-40db-b513-50e9d0dd6fb3n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0f563565-42a0-40db-b513-50e9d0dd6fb3n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/30ba487b-a227-4ba8-a67f-a0c2590143f1n%40googlegroups.com.