View Full Version : OT: C++inline void or void
01-31-2001, 01:40 AM
can anyone tell me when it is more better to use inline functions and when normal functions.
Lets say i have
would it be better to use a inline function?
01-31-2001, 02:27 AM
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...
01-31-2001, 02:48 AM
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).]
01-31-2001, 03:55 AM
Anyone tried to inline a recursive function? http://www.opengl.org/discussion_boards/ubb/smile.gif
01-31-2001, 04:06 AM
You ask for trouble when you do that. http://www.opengl.org/discussion_boards/ubb/tongue.gif
01-31-2001, 04:38 AM
thx for your replies.
Taken my example from above would you take an inline function or not???
Good C++ rule of thumb is do not inline unless you need it. Exception to that or get and set fonctions which only return or set a parameter if they do not require a new include file the header file(for small projects, you can simply forget about the if).
So your function wouldn't be inline. But if later in your program, you see that the call overhead is killing you because it is getting called often, then inline it. My first bet is you probably won't need to inline it.
This fonction is actually really easy to inline for compilers because it is not dependant on anything, it is totally self-contained. So unless one of the glCall is inline(which is impossible) because they come from a dll then
inlining is trivial.
inline of recursive fonctions is possible if you tweak the compiler options correctly( depth unrolling, etc..), but it is not portable and simply not recommended because from my experience, it will simply crap out!!
01-31-2001, 05:10 AM
thx Gorg...i will do it that way
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.