I am trying to implement a simple 3D software engine. So I need a 4x4 matrix to convert. Each cell type of my matrix is in the System.Double format, which means that the whole matrix will use 8 bytes * 16 cells = 128 bytes. I currently implemented this as a class. Also, this matrix is an immutable type. So, now when I try to multiply a vector by this matrix, I am doing something like this: matrix.m11 * vector.X (etc.). It seems to me that to access the field m11, the program first needs to get the "matrix" reference value, and then check it for zero, and then find the M11 value, right? If I changed the class to structure, could my multiplication be much faster? I know that 128 bytes of struct are big, but if I write a method,which only works using ref / out keyowrds? Will it be a good chooose?
As I see in the SharpDX library, a matrix is a structure. Should I change the class to structure in order to improve performance?
source
share