2 ms·
Go's memory model has similarities to C. For instance you can use the heap or the stack. Go figures out which one an allocation should live in by doing escape a
by zaphar 14y ago
Go's memory model has similarities to C. For instance you can use the heap or the stack. Go figures out which one an allocation should live in by doing escape analysis. If it never leaves the function it goes on the stack. If it does it goes on the heap. GC ensures anything on the heap gets cleaned up. It's not an API.
- pcwalton 14y agoTo be fair, Java does escape analysis for this too. This isn't a difference between Java and Go.
- Locke1689 14y agoBoth the JVM and the CLR do this. This is not a Go technology. In fact, in certain cases the JVM can detect type information and remove the allocation entirely by hoisting integer fields and the like into registers.
- ericbb 14y agoIt's not about escape analysis. The programmer explicitly specifies when to use pointers. Whenever pointers are not used, the object is stored in-place (for example, on the stack, in the array or slice, or in the struct).