# OT: C++inline void or void

can anyone tell me when it is more better to use inline functions and when normal functions.

Lets say i have

void TexGen::SafeMatrix()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
}

would it be better to use a inline function?

thx
Chris

Hi,

When you call a function the execution point is taken to the adress where this function is declared and taken back after the execution is finished. (thinking in assembly way…)

This operation (change the execution point to another adress) spend time. And I mean here “instruction time”.

If you call a small function like a simple atribution, the system would spend more time to change to the function adress then executing the function itself.

When you declare an inline function, the compiler “copy” the instruction to all the points where the function was called. This eliminates the time spent with changing the execution poit. But obviously increses the “exe” size.

Then it depends on how many times you called the function in your code…

This inline stuff is quite complicated to explain… let me know if didn’t understand and I’ll try to be clearer.
Hope it helps…

Yes, when to inline a function or not, depends on how large the function is, and how many times the function is used. In the end you may want to just profile the code with the function inlined and not inlined to see which is better. Too much inlining can increase the frequency of cache misses.

[This message has been edited by DFrey (edited 01-31-2001).]

Anyone tried to inline a recursive function?

You ask for trouble when you do that.