3 ms·
Its discussion of stack vs heap is not entirely accurate: // memory allocated on heap: ptr := new(int) *ptr = 7 Depending on how ptr is used, esca
by Jabbles 10y ago
Its discussion of stack vs heap is not entirely accurate:
// memory allocated on heap:
ptr := new(int)
*ptr = 7
Depending on how ptr is used, escape analysis may place *ptr on the stack. Also note that the terms stack and heap are not directly comparable between languages anyway.
- zzzcpan 10y agoThe biggest difference is that you cannot actually force Go to allocate on stack (which is the only important use case in this context), the escape analysis only works for primitive cases, but throw a higher order function into it and it fails.