3 ms·
Just because it has a garbage collector doesn't mean it's suboptimal; Go's GC is much faster and less intrusive than that in other languages, and unlike Java, y
by Cthulhu_ 4y ago
Just because it has a garbage collector doesn't mean it's suboptimal; Go's GC is much faster and less intrusive than that in other languages, and unlike Java, you actually get to choose whether you put things on the heap or stack so you can in theory avoid using the heap entirely, if it makes sense for your application.
- benhoyt 4y ago> you actually get to choose whether you put things on the heap or stack I think I know what you mean, but this isn't strictly true. In Go, the compiler decides for you, and you don't have to worry about it. The compiler allocates on the stack whenever it can (because it's faster and uses less memory), but if it determines that a variable "escapes the stack" or if it can't figure out whether it escapes or not, it allocates on the heap. You could have a simplistic (but correct) Go compiler which allocated everything on the heap -- interestingly, the Go spec doesn't mention the words "heap" or "stack" at all. Go does give you a lot of control over allocations (stack or heap!) and memory layout, though, which makes it pretty good for relatively low-level performance work.