Mun*_*oup 5 go escape-analysis
func main() {
i1 := 1
A1(&i1)
}
func A1(i1 *int) *int {
return i1
}
逃逸分析的结果是
./main.go:18:9: parameter i1 leaks to \~r1 with derefs=0:
./main.go:18:9: flow: \~r1 = i1:
./main.go:18:9: from return i1 (return) at ./main.go:19:2
./main.go:18:9: leaking param: i1 to result \~r1 level=0
parameter i1 leaks to \~r1 with derefs=0leaking param: i1 to result \~r1 level=0
golang escape leaking
“你为什么那么想?” 可以合理地假设泄漏是不好的并且与其阀杆泄漏有关。我正在努力想一个泄漏是一件好事的示例上下文,例如泄漏桶、泄漏储气罐、泄漏、泄漏电容器、泄漏船、泄漏抽象。对于高性能 Go 专家来说这可能是显而易见的,但对于我们其他人来说,链接到文档并简要说明泄漏参数所指的内容会很有帮助
这是我想问的同一个问题,但在此之后不再回复。
然后我尝试阅读打印这些结果的源代码。
// 泄漏表示来自参数的一组分配流
// 到堆或它的任何函数(第一个 numEscResults)
// 结果参数。
但是我无法理解这一点,是否有任何官方文件可以代表它。
numEscResults(7)
func main() {
i1, i2, i3, i4, i5, i6, i7, i8, i9 := 1, 1, 1, 1, 1, 1, 1, 1, 1
A1(&i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9)
return
}
func A1(i1, i2, i3, i4, i5, i6, i7, i8, i9 *int) (*int, *int, *int, *int, *int, *int, *int, *int, *int) {
return i1, i2, i3, i4, i5, i6, i7, i8, i9
}
...some duplicate output
./main.go:16:13: leaking param: i2 to result ~r10 level=0
./main.go:16:17: leaking param: i3 to result ~r11 level=0
./main.go:16:21: leaking param: i4 to result ~r12 level=0
./main.go:16:25: leaking param: i5 to result ~r13 level=0
./main.go:16:29: leaking param: i6 to result ~r14 level=0
./main.go:16:33: leaking param: i7 to result ~r15 level=0
./main.go:16:37: leaking param: i8
./main.go:16:41: leaking param: i9
./main.go:8:30: i8 escapes to heap:
./main.go:8:30: flow: {heap} = &i8:
./main.go:8:30: from &i8 (address-of) at ./main.go:9:40
./main.go:8:30: from A1(&i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9) (call parameter) at ./main.go:9:4
./main.go:8:34: i9 escapes to heap:
./main.go:8:34: flow: {heap} = &i9:
./main.go:8:34: from &i9 (address-of) at ./main.go:9:45
./main.go:8:34: from A1(&i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9) (call parameter) at ./main.go:9:4
./main.go:8:30: moved to heap: i8
./main.go:8:34: moved to heap: i9