3 ms·
XNA doesn't even have a generational GC, which makes writing games feel like a constant exercise in tricking the GC. The GC's marking phase is very slow becaus
by mkilling 15y ago
XNA doesn't even have a generational GC, which makes writing games feel like a constant exercise in tricking the GC.
The GC's marking phase is very slow because it has to traverse the whole object graph each time, meaning you want to make the object graph as simple as possible.
Arrays of structs are very efficient for the GC to scan (it can either collect the whole array or not), but working with structs is a nightmare because there's no polymorphism.
For Fluffy[1] we just used classes and tried to optimize the hotspots as an afterthought. I'm not quite satisfied with how it turned out, there's still a periodical 20-40ms lag in the game.
There is a great article about keeping heap complexity low: http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-pat...
[1] http://marketplace.xbox.com/en-US/Product/Fluffy-Operation-Overkill/66acd000-77fe-1000-9115-d802585508be http://marketplace.xbox.com/en-US/Product/Fluffy-Operation-O...
- elisee 15y agoOn Xbox 360, XNA comes with the .NET Compact Framework which indeed includes a pared-down, non-generational GC (http://msdn.microsoft.com/en-us/library/bb203912.aspx http://msdn.microsoft.com/en-us/library/bb203912.aspx). (On Windows though you get a full .NET framework.) As a developer for Xbox 360, I found your best bet is to: - monitor the amount of memory allocated (print out GC.GetTotalMemory(false)) - allocate everything during loading and force a GC when you're done loading stuff. - ensure you're not creating any garbage at all during your main loop, which will prevent the GC from kicking in at all.