Is better to declare as class level variables?

I'm working off from Derek Pierson's tutorial series, and in his Skybox Render() sub he declares these matrix variables and assigns these other properties.

Dim worldMatrix As Matrix = Matrix.Identity

Dim viewMatrix As Matrix

viewMatrix.M41 = 0.0F

viewMatrix.M42 = 0.0F

viewMatrix.M43 = 0.0F

Since they don't ever change during application run, I was thinking they should be declared just once as class level instead of per frame.

How much performance difference would a small change like that make




Answer this question

Is better to declare as class level variables?

  • reminvestor

    Not a whole lot. Creating an instance of a class is NOT the hard work being done by a DX app. But, it makes sense, so try it and see if you can notice a difference. It will at least make the code cleaner.



  • Is better to declare as class level variables?