
05-04-2011, 02:17 AM
|
Approved Member
|
|
Join Date: Mar 2011
Posts: 812
|
|
Quote:
The biggest one by far is garbage. the .net garbage collector on windows does a fantastic job, and you can get away without baby sitting it for the most part. On the xbox/winPhone7 thats a different matter. If you get stalls every few frames, garbage collection might be causing you problems. At the moment it triggers after every 1mb allocation.
Heres some tips for dealing with garbage. You shouldn't have to worry about most of these in reality, but they may come in handy one day.
* Draw the contents of GC.GetTotalMemory() to the screen. This gives you an approximation of the ammount of allocated bytes your game uses. If it hardly moves, your doing ok. If its going up fast, you have issues.
* try to allocate all your heap objects up front. If you do allocate eveything before the game starts, everytime you hit a meg of allocations, your going to stall. No allocations, no collections. as simple as that.
* After loading, call GC.Collect(). If you know most of your big allocations are out the way, its only nice to let the system know.
* DO NOT CALL GC.Collect() every frame. It might seem like a good idea, keeping on top of your garbage and all that, but remember the only with worse than a garbage collection is over garbage collection.
* Look for where your garbage is coming from. There are some common causes like concatnating strings instead of useing StringBuilder (bewhere, StringBuilder isnt a magic bullet, and can still cause allocations!. This means simple operations like adding a number to the end of a string can create surprising amounts of garbage.) or using foreach loops over collections that use the IEnumerable interface can also create garbage without you knowing (for eaxmple, foreach (EffectPass pass in effect.CurrentTechnique.Passes) is a common one)
* Use tools like the CLR memory profiler to figure out where memory is being allocated. There are loads of tutorials out there on how to use this tool.
* When you know where your allocating during gameplay, see if you can use tricks like pooling objects to lower that allocation count.
* If all else fails, make your collections run faster! The GC on the compact framework follows evey reference in your code to figure out what objects are not in use anymore. Refactor your code use less references!
* Remember to use IDisposable on classes that contain unmanaged resources. You can use these to clean up memory the GC cannot free up itself.
|
Am i close Luthier?  is this game programed in C# entirely?
__________________
Gigabyte Z68
Intel 2500K (@4.3 ghz)212 CM Cooler
8GB Ram
EVGA 660SC (super clocked) 2GB Vram
CORSAIR CMPSU-750TX 750W
64 GB SSD SATA II HD
WIN7 UL 64BIT
|