|
|
|
|
|
by anonacct38
1892 days ago
|
|
& doesn't always imply a value is on the heap. Escape analysis will ensure that pointers to the stack are safe. Here's an example with a bit of explanation: if you pass a value to fmt.Println it will escape. The raw println builtin does not cause values to escape. So calling the first function twice and seeing the same address for the value strongly implies stack allocation while calling the 2nd function twice and getting different addresses implies heap allocation. https://play.golang.org/p/PSb1wj1-x1c |
|
Thank you for explaining what's going on there! :)
And btw, compiling the above example with -gcflags="-m" (which I learned about earlier today) proves you right.