4 ms·
> If at some point it will be possible to disable the garbage collector and manually manage memory, .NET could be used for everything. While I haven't seen any
by throwuxiytayq 5y ago
> If at some point it will be possible to disable the garbage collector and manually manage memory, .NET could be used for everything.
While I haven't seen anyone disable the GC completely, plenty of people avoid using it in the Unity/gamedev world. You simply avoid allocating memory (outside of loading) and the GC isn't a problem when it has no work to do. Making sure none of your code allocates at runtime is only difficult if you "don't optimize prematurely" (write shit code without any understanding or regard for performance).
- mapmap 5y agoWhat is the technique to do this? Object pools?
- throwuxiytayq 5y agoIn case of Unity specifically, yes, re-using entire GameObjects whenever possible goes a long way. In game code, you can use structs instead of managed objects to avoid touching the GC. Unity provides NativeCollections, which are some standard collection data structures that can be used to store structs outside managed memory (which lets you avoid the GC). In real life it's next to impossible to avoid GC completely (especially if you rely on assets/libraries/even built-in engine features), but that isn't the goal - it's enough that you avoid allocating managed objects during gameplay simulation. GC can do its thing during level loading, cutscenes, in UI, etc.
- hackerfromthefu 5y agoYes, also know as Flyweight pattern from GOF. Used in latency sensitive systems like trading engines.