Understanding the Cost of Methods

One of the most important ways to ensure that you write applications with the best performance is to always know the cost of any method you call. Although memorizing all the different permutations of APIs you can call and the performance they take is unreasonable, you should have at least a vague idea about the cost of any method.

Managed DirectX has a few cases where seemingly harmless code can cause problems. For example, any method that takes a string as an argument in Managed DirectX has the cost of allocating a new unmanaged string type and copying the string data over.

Take the case where you are using High-Level Shader Language (HLSL) to render your scene, and numerous times throughout each frame, you ...

Get Beginning 3D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.