Skip to main content
GameDev.net gamedev.net
🔒 Locked

URGENT : __forceinline

Started by clapton Nov 26, 2004 at 4:04 PM 9 replies 3.6k views
Original Post
clapton
clapton
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!
___Quote: Know where basis goes, know where rest goes.
chollida1
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
CheersChris
clapton
clapton
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 ! :)
___Quote: Know where basis goes, know where rest goes.
ziruz
ziruz
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
pjcast
pjcast
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.
Russell
Russell
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.
pjcast
pjcast
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.
iMalc
iMalc
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.
iMalc
iMalc
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.
Arcibald Wearlot
Arcibald Wearlot
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.