News for hackers. Stuff that matters.
Re:Why I Write Games in C (yes, C) by omaranto on Saturday September 21, 2019 @07:30PM (#21038588)
Does Go really let you use closures, arrays, slices and maps when you disable the garbage collector? If so, does that just leak memory?
Re:Why I Write Games in C (yes, C) by weberc2 on Saturday September 21, 2019 @08:37PM (#21038853)
Yes, the idea is that you must invoke the GC when you’re not in a critical section. Alternatively you can just avoid allocations using arenas or similar. (You can use arrays and slices without the GC).
Re:Why I Write Games in C (yes, C) by omaranto on Sunday September 22, 2019 @09:59AM (#21041383)
To make sure I understand, is this an accurate expansion of your comment?

Yes it would leak, to avoid leaking you could invoke the GC when you’re not in a critical section. Alternatively, if you don't use maps and instead structure all your data into arrays, slices and structs, you can just avoid allocations using arenas or similar. (You can use arrays and slices without the GC, but maps require it).

Re:Why I Write Games in C (yes, C) by weberc2 on Sunday September 22, 2019 @10:30AM (#21041511)
Yes, that is correct. Anything that allocates on the heap requires GC or it will leak memory. Go doesn’t have formal semantics about what allocates on the heap and what allocates on the stack, but it’s more or less intuitive and the toolchain can tell you where your allocations are so you can optimize them away. If you’re putting effort into minimizing allocations, you can probably even leave the GC on and the pause times will likely be well under 1ms.