Game Development Reference
In-Depth Information
The more types in an assembly, the more memory it will take up and the more
time it will take to be JIT'ed. Consider moving types that are rarely used into sep-
arate assemblies that can be loaded into a second AppDomain on demand. The same
goes for large resources; keep them in external assemblies instead of embedding
them into the main assembly. Lastly, if you are only using a couple methods out of
a fairly large assembly, you might consider implementing your own copy of those
methods to avoid having to load the assembly.
Note
You can use the VaDump tool, downloadable from Microsoft.com, to track your working set. You can
also use Performance Counters ( perfmon.exe ) to give you detailed feedback about a number of
useful statistics like the number of classes that you load.
The .NET platform provides transparent support for automatic memory manage-
ment, but there are some tasks that you should explicitly do in order to design for
optimum performance. The first task is to ensure that Dispose() is called on the
appropriate objects as soon as possible. Also, ensure that you do not reference
objects once you are done using them. References to unused objects will prevent
the garbage collector from collecting and removing the objects from the applica-
tion memory.
Perform Chunky Calls
There are generally two types of calls when working with data across managed and
unmanaged interfaces: “chatty” and “chunky.” Chatty calls are those that occur
quite often and do very little work, while chunky calls are those that occur less fre-
quently, but generally do more work when they occur.
I should mention that chunky calls are not always the best solution. A chatty call
that passes simple data may be less computationally expensive than a chunky call.
The incurred performance costs are cheaper because the data marshaling is not as
complex. P/Invoke , Interop , and Remoting calls all carry significant overhead, so you
want to minimize the number of calls using them. The best approach is to proto-
type both call types early in the development phase so that you can make the best
decision for the solution.
When a call is sent between managed and unmanaged code, there are some events
that transpire in order to facilitate this communication. First, data marshaling
must be performed to get the source data into the appropriate target format for
the receiver. Next, the calling convention signatures must be fixed to pass data
 
Search Nedrilad ::




Custom Search