3 ms·
Sure, but it's also worth pointing out that the class of programs that behave this way is the class of programs that are inefficient to begin with. If you hand
by jblow 10y ago
Sure, but it's also worth pointing out that the class of programs that behave this way is the class of programs that are inefficient to begin with.
If you handle strings, and you are copying and freeing strings all the time, that's just slow code.
And it's not the case that GC makes the slow code faster... it's that certain techniques enable GC to not fail catastrophically on slow code.
It's a little bit disturbing that folks are ready to extrapolate this to some kind of universal rule.
In a high-end video game, for example, we hardly allocate anything short-term at runtime. The whole program is architected to avoid it. When we allocate, it tends to be things with medium-to-long-term life (texture maps, sound effects, render targets, whatever) so a generational system is useless there. In fact we don't use GC on these kinds of things at all, because we also need to control exactly when they are deallocated so we can put something in their place, because memory is limited.
- AlphaSite 10y agoYou have things that only live for a short while do you not? Object pooling, stack allocation, etc are designed to solve that problem as I understand it.
- phantarch 10y agoWhile the objects in the pools or stacks may seem transient (on your screen for only a few moments), one simple technique is to only allocate those objects at load time and then flip them in an "on" or "off" state during gameplay. That way you're not doing any real allocation after your game space has loaded.
- jblow 10y agoNo, those are only seen as "ways to solve the problem" by the functional-style programmers who created the problem in the first place. Stack allocation is what your computer is built from the ground up to do. It is not some kind of workaround or optimization, it is how software was originally designed to work.
- mike_hearn 10y agoGame engines are strongly generational too, you just don't notice because the short lived allocations are all put on the stack by the developer.
- jblow 10y agoI think at this point you are abusing terminology such that it's meaningless. I am not just talking about putting copies of things on the stack, but having few copies to begin with, etc.