Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: OT: C++inline void or void

  1. #1
    Junior Member Newbie
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    15

    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
    Code :
    void TexGen::SafeMatrix()
    {
    	glMatrixMode(GL_PROJECTION);
    	glPushMatrix();
    	glLoadIdentity();
     
    	glMatrixMode(GL_MODELVIEW);
    	glPushMatrix();
    	glLoadIdentity();
    }
    would it be better to use a inline function?

    thx
    Chris
    yes

  2. #2
    Intern Contributor
    Join Date
    Jan 2001
    Posts
    60

    Re: OT: C++inline void or void

    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...

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: OT: C++inline void or void

    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).]

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    Re: OT: C++inline void or void

    Anyone tried to inline a recursive function?
    - Michael Steinberg

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: OT: C++inline void or void

    You ask for trouble when you do that.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    15

    Re: OT: C++inline void or void

    thx for your replies.
    Taken my example from above would you take an inline function or not???
    yes

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    662

    Re: OT: C++inline void or void

    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!!

  8. #8
    Junior Member Newbie
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    15

    Re: OT: C++inline void or void

    thx Gorg...i will do it that way
    yes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •