Jump to content
  • Advertisement
Sign in to follow this  
clapton

URGENT : __forceinline

This topic is 5047 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

Heeeelp!! Today I thought to myself that I would do a little cleaning to my C++ project. I just wanted to separate class definitions from their member functions code. Before I divided the classes to source/header files all the functions were considered to be inline expanded (since they were fully listed in each class' header). Now everything is like I planned - clean and tidy. Unfortunately, the performance of the application dropped very noticeably and I guess it can be caused by the lack of inline expansion. My problem is - how to use __forceinline keyword. Each time I add it before function name I get linker errors (MSVC++ 7.0). Great thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
First off, I doubt the performance is caused by a lack of inline expansion. Usually forcing inlining reduces your preformance due to bloated code. Infact there was a post on the DX mailing list saying it was build for size rather than speed, to get better performance.

As for inlining. CHeck out the #pragma options.

CHeers
CHris

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
First off, I doubt the performance is caused by a lack of inline expansion. Usually forcing inlining reduces your preformance due to bloated code.


That's the first thing I thought... and after more detailed checking (read->rebooting the system) it fortunately appeared to be true. :D It was just a moment of CPU overload.

Thanks ! :)

Share this post


Link to post
Share on other sites
did you move inline functions to a cpp?
thats not possible, the definitons of the functions must be aviable
in the same file as the declaration.
it is like this because other wise the compiler can't insert the code at compile-time...

// ziruz

Share this post


Link to post
Share on other sites
Just for your info, the linking errors you were getting were probably caused because you seperated out your method(s) code from the header into a seperate cpp file...

If you have:

whatever.h
class whatever
{
inline void myMethod();
};


whatever.cpp

void whatever::myMethod()
{
}


The method will be (upto compiler really) inlined fine for other methods in same cpp file calling it. But, you error is that you were probably trying to call that code from another compilation unit (cpp file), in which case the method needs to be inside a header file.

Share this post


Link to post
Share on other sites
Quote:
Original post by ziruz
it is like this because other wise the compiler can't insert the code at compile-time...


Not true. The Intel and Microsoft compilers can inline from a source file, if you enable such optimizations.

Also, __forceinline does not guarentee that a function will be inlined.

Share this post


Link to post
Share on other sites
Yes, the compiler can inline such functions, but only in the current compilation unit. If you wish to have other source files use the inline, you need to declare & define the function in the header file.. http://www.parashift.com/c++-faq-lite/inline-functions.html

I did read that using "extern inline" can overcome that, but I don't know how standard that is.

Share this post


Link to post
Share on other sites
If they are reasonably small functions then define them within the class definition in the .h (cough, ahem...) .hpp file and the compiler should always try and inline them for you if appropriate.

Any chance you can profile the before and after and verify that it is indeed lack of inlining?

Also, by modularising your program you may have actually accidentally created, or fixed a bug, which impacts on performance.

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
First off, I doubt the performance is caused by a lack of inline expansion. Usually forcing inlining reduces your preformance due to bloated code. Infact there was a post on the DX mailing list saying it was build for size rather than speed, to get better performance.

As for inlining. CHeck out the #pragma options.

CHeers
CHris
Yeah, I don't think loop unrolling optimisations take into account your code cache size. How ironic that it's sometimes slower. I often optimise for size anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by pjcast
whatever.h
class whatever
{
inline void myMethod();
};


whatever.cpp

void whatever::myMethod()
{
}


Just a bit OT, shouldn't the inline keyword be used in the function definition and not in the declaration?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!