inline

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • InuY4sha

    inline

    What do I gain from defining a [small] function as inline?
    Thanks
    R
  • InuY4sha

    #2
    Re: inline

    Sorry ... I should have googled a bit ...

    InuY4sha ha scritto:
    What do I gain from defining a [small] function as inline?
    Thanks
    R

    Comment

    • Malcolm McLean

      #3
      Re: inline

      "InuY4sha" <inuY4sha@email .itwrote in message
      news:75a8e19a-2407-4c27-b767-978da923f0dd@i3 6g2000prf.googl egroups.com...
      What do I gain from defining a [small] function as inline?
      Thanks
      >
      Usually nothing. With optimisation set high, a decent compiler will do this
      for you.

      --
      Free games and programming goodies.


      Comment

      • D. Webb

        #4
        Re: inline

        On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
        InuY4sha <inuY4sha@email .itwrote:
        What do I gain from defining a [small] function as inline?
        Thanks
        R
        In case you haven't found the answer you were looking for, I'll give it
        a shot:

        Calling a function has a (small) amount of overhead to it: things
        (i.e., return address and function arguments) need to be pushed and
        popped off of the stack, and jumps need to be made to different points
        in the program.

        If a function is "sufficient ly" small (only a few lines), then the
        overhead of actually calling a function may become a significant
        portion of the function's execution time.

        By inline'ing the function, a copy of the functions body is compiled
        in-place wherever it is called in the program, thus eliminating the
        actual call during runtime, and *maybe* getting small performance
        increase.

        As Malcolm said, this is usually one of the optimizations a compiler
        will do automatically for you, but hopefully now you have a better
        understanding of why it does it.

        D. Webb

        Comment

        • swengineer001@gmail.com

          #5
          Re: inline

          On Apr 8, 1:07 pm, "D. Webb" <devnull...@yah oo.comwrote:
          On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
          >
          InuY4sha <inuY4...@email .itwrote:
          What do I gain from defining a [small] function as inline?
          Thanks
          R
          >
          In case you haven't found the answer you were looking for, I'll give it
          a shot:
          >
          Calling a function has a (small) amount of overhead to it: things
          (i.e., return address and function arguments) need to be pushed and
          popped off of the stack, and jumps need to be made to different points
          in the program.
          >
          If a function is "sufficient ly" small (only a few lines), then the
          overhead of actually calling a function may become a significant
          portion of the function's execution time.
          >
          By inline'ing the function, a copy of the functions body is compiled
          in-place wherever it is called in the program, thus eliminating the
          actual call during runtime, and *maybe* getting small performance
          increase.
          >
          This is not required at all. According to section 6.7.4 of the
          standard "Making a function an inline function suggests that calls to
          the function be as fast as possible. The extent to which such
          suggestions are effective is implementation-defined." In other words
          inline may do as you suggest. It may also perform some other form of
          optimization to increase the speed of the function. It may only
          perform optimizations for some of your inline functions based on some
          criteria defined by the implementer. It it may in fact do nothing at
          all.

          Comment

          Working...