inline

  • Follow


What do I gain from defining a [small] function as inline?
Thanks
R
0
Reply inuY4sha1 (12) 4/8/2008 2:41:59 PM

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

InuY4sha ha scritto:

> What do I gain from defining a [small] function as inline?
> Thanks
> R
0
Reply inuY4sha1 (12) 4/8/2008 2:49:09 PM


"InuY4sha" <inuY4sha@email.it> wrote in message 
news:75a8e19a-2407-4c27-b767-978da923f0dd@i36g2000prf.googlegroups.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.
http://www.personal.leeds.ac.uk/~bgy1mm

0
Reply regniztar (3128) 4/8/2008 2:50:54 PM

On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
InuY4sha <inuY4sha@email.it> 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
0
Reply devnull431 (1) 4/8/2008 5:07:04 PM

On Apr 8, 1:07=A0pm, "D. Webb" <devnull...@yahoo.com> wrote:
> On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
>
> InuY4sha <inuY4...@email.it> 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.
0
Reply swengineer001 (71) 4/9/2008 2:28:52 AM

4 Replies
32 Views

(page loaded in 0.376 seconds)

Similiar Articles:
















6/19/2012 6:26:22 AM


Reply: