4 ms·
> Examples of hidden allocations: > Go’s defer allocates memory to a function-local stack. Not really hidden if there's keyword indicating it's happening, no?
by dymk 3y ago
> Examples of hidden allocations:
> Go’s defer allocates memory to a function-local stack.
Not really hidden if there's keyword indicating it's happening, no? I guess you could argue that "defer" isn't called "defer_and_allocate", but on the other hand, the docs make it clear that it allocates.
- hellcow 3y agoI think it’s fair to say that knowing what allocates in Go requires in-depth knowledge of its internals, well beyond the `defer` example. Every possible allocation is not obvious to the typical Go programmer. It is obvious in Zig.
- vacuity 3y agoAlthough with a language like Go, I would think programmers should expect that allocations occur frequently, and rely on the GC and language design to ensure decent performance or whatever is being asked for. It won't hold true all the time and sometimes more knowledge is needed, but the baseline wouldn't involve that.