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

Started by
4 comments, last by Namethatnobodyelsetook 18 years, 9 months ago
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.
Advertisement
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.
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
Like i said, tweak your compilation settings to allow for link time inlining.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

I'm pretty sure RVO was a .NET 7.1 (ie: 2003) big feature, and 7 (2002) doesn't do it. I could be wrong, but that's what I remember.

This topic is closed to new replies.

Advertisement