| ▲ | knorker 4 days ago | |
Agreed that it could in principle. But I can't immediately get it to do so: https://go.dev/play/p/9hLHattS8cf Both arrays in this example seem to be on the heap. | ||
| ▲ | simiones 3 days ago | parent [-] | |
Taking the address of those variables makes them escape to heap. Even sending them to the Printf function makes them escape to heap. If you want to confirm, you have to use the Go compiler directly. Take the following code:
And compile it with
However, if you return logs2, or if you take the address, or if you pass them to Printf with %v to print them, you'll see that they now escape.An additional note: in your original code from your initial reply, everything you allocate escapes to heap as well. You can confirm in a similar way. | ||