Optimization

Started by
4 comments, last by sjelkjd 18 years, 10 months ago
Hi, how much optimization does Visual Studio do when all the optimization flaggs are set? (For c#) For example, i have a 4x4 Matrix struct, with a constructor that takes a bool and creates a zero matrix or identity matrix. Now, does the constructor create a matrix, then copy the new matrix into the desired location, or does it create the desired matrix in the desired location? should i instead make a function build matrix that takes a "out Matrix" and a boolean and returns void. thanks Yratelev
Yratelev
Advertisement
Depends how you wrote it, and on your compiler. An initializer list is your best bet generally, but AFAIK there isn't a way to set those up with arrays. The most accurate answer to your question will come from looking at the assembly output. In any case, the proposed creation function is highly unlikely to help matters, unless I'm not thinking clearly about it. :/
C# never does any copying, unless you explicitely do it yourself. In he constructor, it is directly placed in the memry where it should be, and fom then on, you are only copying the references.
cheers quasar3d

Yratelev
Yratelev
That is to say, you can return a huge object from a function and it will be as fast as passing it as an out parameter.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
>>C# never does any copying, unless you explicitely do it yourself.

That it not true - value types are copied when they are passed to functions, and also when they are returned from functions. A further implication of this is that functions manipulating large value types are unlikely to be inlined, since .net tends not to inline functions that take up more than 32 bytes of IL, including parameters(this may chance in 2.0).

This topic is closed to new replies.

Advertisement