Jump to content
  • Advertisement
Sign in to follow this  
Yratelev

Optimization

This topic is 4721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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. :/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
>>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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!