3 ms·
To be fair, Go's GC got A LOT better over the past few versions and it's getting much better still. What I would really like to be able to do though is be able
by inglor 10y ago
To be fair, Go's GC got A LOT better over the past few versions and it's getting much better still.
What I would really like to be able to do though is be able to write unmanaged blocks when I need them and know better than the compiler rather than having to "run my own heap" on top of a buffer like I typically have to do in managed languages that don't have that opt out.
- yxhuvud 10y agoCrystal might be worth checking out if you have that kind of need.
- weberc2 10y agoHave you considered pausing the GC for those blocks? Or am I misunderstanding your use case?
- infogulch 10y agoHow do you do this? I didn't know there was a way to temporarily disable the GC for specific blocks.
- weberc2 10y agoYou can toggle the GC with https://golang.org/pkg/runtime/debug/#SetGCPercent https://golang.org/pkg/runtime/debug/#SetGCPercent. Turn it off before you enter your block and enable it again at the end of your block.
- amelius 10y agoBut can you guarantee that the GC actually makes progress that way?
- weberc2 10y agoWhat does it mean for a GC to "make progress"? My understanding was that the OP wanted to stop the GC for a particular code block, so it would seem that any "progress making" would be undesirable.
- AnimalMuppet 10y agoMaybe you can, but maybe you shouldn't. That is, you do this if you want a block to run without the GC interrupting it. That is, it's a really high-priority (realtime, or close) block. When it needs to run, it's the most important use of the CPU. But if you demand that the GC makes progress, you're saying that it also is important. And it is, but it's less important than the critical block. If you don't say that, then you wind up with "everything is important", and that way lies madness. But you may be able to do it. You need enough CPU bandwidth that you can run your critical sections and spend enough time outside them that the garbage collector keeps up. (And then, every time you add to your code, you need to make sure that the CPU still has enough time...)
- kyrra 10y agohttps://golang.org/pkg/runtime/debug/#SetGCPercent https://golang.org/pkg/runtime/debug/#SetGCPercent Do note that it triggers a GC when you call this, so it's not for all situations, but can be useful.