inline

Discussion in 'C Programming' started by InuY4sha, Apr 8, 2008.

  1. InuY4sha

    InuY4sha Guest

    What do I gain from defining a [small] function as inline?
    Thanks
    R
    InuY4sha, Apr 8, 2008
    #1
    1. Advertising

  2. InuY4sha

    InuY4sha Guest

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

    InuY4sha ha scritto:

    > What do I gain from defining a [small] function as inline?
    > Thanks
    > R
    InuY4sha, Apr 8, 2008
    #2
    1. Advertising

  3. InuY4sha

    D. Webb Guest

    On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
    InuY4sha <> wrote:

    > 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 "sufficiently" 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
    D. Webb, Apr 8, 2008
    #3
  4. InuY4sha

    Guest

    On Apr 8, 1:07 pm, "D. Webb" <> wrote:
    > On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
    >
    > InuY4sha <> wrote:
    > > 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 "sufficiently" 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.
    , Apr 9, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhi
    Replies:
    2
    Views:
    725
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    465
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    450
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,831
    Kevin Bracey
    Nov 21, 2003
  5. Nish
    Replies:
    4
    Views:
    479
    Thomas Stegen
    Oct 8, 2004
Loading...

Share This Page