Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: hImagehlpDll = LoadLibrary((LPCWSTR)L"imagehlp.dll" ); this WORKED Pin
ForNow18-Apr-08 6:21
ForNow18-Apr-08 6:21 
QuestionRe: hImagehlpDll = LoadLibrary((LPCWSTR)L"imagehlp.dll" ); this WORKED Pin
David Crow18-Apr-08 7:02
David Crow18-Apr-08 7:02 
GeneralRe: hImagehlpDll = LoadLibrary((LPCWSTR)L"imagehlp.dll" ); this WORKED Pin
ForNow18-Apr-08 11:42
ForNow18-Apr-08 11:42 
Generalinline Pin
User 58385216-Apr-08 13:12
User 58385216-Apr-08 13:12 
GeneralRe: inline Pin
Stephen Hewitt16-Apr-08 15:10
Stephen Hewitt16-Apr-08 15:10 
GeneralRe: inline Pin
User 58385216-Apr-08 15:17
User 58385216-Apr-08 15:17 
GeneralRe: inline Pin
Randor 16-Apr-08 16:13
professional Randor 16-Apr-08 16:13 
GeneralRe: inline Pin
Randor 16-Apr-08 16:10
professional Randor 16-Apr-08 16:10 
Josh Gray wrote:
1) Do you use it?


Actually recent Microsoft compilers are fairly good at determining which functions to inline. I still use it to make sure the compiler gets the hint. It should be noted that the __inline keyword is simply a compiler hint and may be completely ignored if the compiler determines its not the best choice. In cases where you want to overide the compilers decision you can use __forceinline. But once again this is simply a hint the compiler may ignore. Although it could be described as a 'strong hint' to the compiler.

Heres a good tip. The only 100% sure method to have your function inlined is to use the #define keyword.

Josh Gray wrote:
2) How do you decide when to use it?


Function calls have overhead, they are not free. The stack and registers of the calling function must be saved and restored. All of ther function arguments are copied into registers... then a stack frame needs to be set up for the local variables in the new function.

I mostly use it for returning member variables such as:

__inline int MyClass::GetVar() const { return myVar; }


If there is work that needs to be done many times in a loop it is sometimes better to inline the function. The compiler may choose to automatically inline the function if it meets whatever criteria. Otherwise you may be force to use __forceinline before the compiler actually takes your advice. It doesn't trust you, and maybe you shouldn't either!

for(int i = 0; i < iSomeLimit;++i)
{
    DoWork(SomeArray[i]); //This function might benefit from inline expansion.
}



Josh Gray wrote:
3) Do you ever actually measure the benifit of using it?

Yes, you can read the RDTSC[^] counter to get a rough idea of the function performance before and after inlining.


Josh Gray wrote:
4) Can using it ever degrade performance?


Yes, most definately!

It is important NOT to inline functions that are very large in size. The reason is that the processor instruction pipeline[^]is always reading ahead and storing future instructions in the pipe so that it can execute it very fast, but it may make a mistake and cache the wrong instructions! While the processor is excuting instructions... it is at the same time trying to predict where the code will JMP to next. This is called branch prediction[^]. So if your function is extremely large it can degrade program performance by increasing page faults and cache misses.

Josh Gray wrote:
5) Can the effect of using it vary on different hardware or operating systems?


Yes.

Optimizations work differently on many flavors of Intel and AMD microprocessors because the instruction pipelines have different sizes/implementation, the branch target buffer[^] may be a different size and they may contain different sizes of L1, L2 and L3 cache.

Inline at your own risk!

Hope this helps,
-David Delaune
GeneralRe: inline Pin
Stephen Hewitt16-Apr-08 16:23
Stephen Hewitt16-Apr-08 16:23 
GeneralRe: inline Pin
cp987616-Apr-08 16:55
cp987616-Apr-08 16:55 
GeneralIE site refresh message Pin
maarchewa16-Apr-08 10:33
maarchewa16-Apr-08 10:33 
GeneralProgramatically determine if windows updates are being installed Pin
nwunder16-Apr-08 9:43
nwunder16-Apr-08 9:43 
QuestionRe: Programatically determine if windows updates are being installed Pin
David Crow16-Apr-08 10:09
David Crow16-Apr-08 10:09 
GeneralRe: Programatically determine if windows updates are being installed Pin
nwunder16-Apr-08 10:40
nwunder16-Apr-08 10:40 
QuestionAssertion failure Pin
sunguy16-Apr-08 6:55
sunguy16-Apr-08 6:55 
GeneralRe: Assertion failure Pin
Cedric Moonen16-Apr-08 7:38
Cedric Moonen16-Apr-08 7:38 
QuestionRe: Assertion failure Pin
David Crow16-Apr-08 10:10
David Crow16-Apr-08 10:10 
GeneralRe: Assertion failure Pin
Moak16-Apr-08 23:58
Moak16-Apr-08 23:58 
QuestionHow do I use GetProcAddress & function pointer? Pin
USAFHokie8016-Apr-08 6:54
USAFHokie8016-Apr-08 6:54 
GeneralRe: How do I use GetProcAddress & function pointer? Pin
Cedric Moonen16-Apr-08 7:40
Cedric Moonen16-Apr-08 7:40 
GeneralRe: How do I use GetProcAddress & function pointer? Pin
USAFHokie8016-Apr-08 8:20
USAFHokie8016-Apr-08 8:20 
GeneralRe: How do I use GetProcAddress & function pointer? Pin
peterchen16-Apr-08 8:41
peterchen16-Apr-08 8:41 
GeneralRe: How do I use GetProcAddress & function pointer? Pin
USAFHokie8016-Apr-08 9:13
USAFHokie8016-Apr-08 9:13 
QuestionRe: How do I use GetProcAddress & function pointer? Pin
David Crow16-Apr-08 10:13
David Crow16-Apr-08 10:13 
QuestionRe: How do I use GetProcAddress & function pointer? Pin
David Crow16-Apr-08 10:12
David Crow16-Apr-08 10:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.