Sign in to follow this  
pi_equals_3

Inlining / Does VC++ 7 .NET do Return Value Optimization?

Recommended Posts

Does anyone out there know for sure if Visual C++ .NET does Return Value Optimization? If so, does it also do Named Return Value Optimization? I can't seem to find anything official on the subject. Also, as a bonus question, if I want a class member function to be able to be inlined in another file, do I need to either stick the definition in the header or include them in a footer file? I have always thought this was necessary, but I've seen member functions declared 'inline' and defined in the accompannying .cpp file with all of the other functions. I seem to be seeing that happen a lot lately.

Share this post


Link to post
Share on other sites
Hi. I used the inline in both the definition and the declaration. And yes it has some optimization, but it depend on the compiler. On VS.net 2002 i think you have to configure it that when it encounter an inline function means it needs to be optimized. Its a good idea to use inline routiens, but is better to do defines or put the code inside the routine which you want to be inlined.

I hope i helped.

Share this post


Link to post
Share on other sites
Yes, VC++.Net can do RVO and NRVO. It also can inline class functions even if they are in another compilation unit. However, taking Dospro's idea of using macro's or just copy/pasting is a BAD IDEA. Mostly because the compiler is generally a lot smarter about knowing when to inline than the programmer. Such premature optimizations tend to cost more time than they save.

Just tweak your compilation settings some, and profile for bottlenecks, the majority of the time those will be algorithm related, and less about how a function was inlined.

Share this post


Link to post
Share on other sites
Thanks for the response, Washu.

In general, when I'm writing important code that gets called often, I try to keep temporary objects in mind, but it's good to know that I can let the compiler do its thing.

I completely agree that premature optimizations aren't a very smart thing. I'm recoding some basic Vector and Matrix classes based on old code, so I already know which key functions inlining can really help. So far I haven't had any problems with letting the compiler decide where to use inline expansion, but it was starting to bother me that the keywords might be ignored completely because of something as little as where the definitions are.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this