3 ms·
Can you elaborate on when an object is "allocated on the stack" versus being "allocated on the heap" in Go?
by euroclydon 17y ago
Can you elaborate on when an object is "allocated on the stack" versus being "allocated on the heap" in Go?
- dkersten 17y agoI cant, since I'm not terribly familiar with Go. Like I said, I assume that this is the reasoning behind supporting pointers, rather than references to everything. I did not actually check.
- dkersten 17y agoThe echo program from the tutorial[1], line 21: var s string = ""; Now, I don't see it written there that it is on the stack, but I imagine so. From the source code of 6g, in cgen.c[2], line 884, you can see this comment: /* * n is on stack, either local variable * or return value from function call. * return n's offset from SP. */ Sounds to me that local variables and return values are always on the stack, which makes sense to me. [1] http://golang.org/doc/go_tutorial.html#tmp_44 http://golang.org/doc/go_tutorial.html#tmp_44 [2] http://code.google.com/p/go/source/browse/src/cmd/6g/cgen.c?r=release http://code.google.com/p/go/source/browse/src/cmd/6g/cgen.c?...