Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > inline

Reply
Thread Tools

inline

 
 
InuY4sha
Guest
Posts: n/a
 
      04-08-2008
What do I gain from defining a [small] function as inline?
Thanks
R
 
Reply With Quote
 
 
 
 
InuY4sha
Guest
Posts: n/a
 
      04-08-2008
Sorry ... I should have googled a bit ...

InuY4sha ha scritto:

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

 
Reply With Quote
 
 
 
 
D. Webb
Guest
Posts: n/a
 
      04-08-2008
On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
InuY4sha <(E-Mail Removed)> 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
 
Reply With Quote
 
swengineer001@gmail.com
Guest
Posts: n/a
 
      04-09-2008
On Apr 8, 1:07*pm, "D. Webb" <(E-Mail Removed)> wrote:
> On Tue, 8 Apr 2008 07:41:59 -0700 (PDT)
>
> InuY4sha <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool which expands implicitly inline inline functions tthunder@gmx.de C++ 3 06-16-2005 12:54 AM
To inline or not to inline? Alvin C++ 7 05-06-2005 03:04 PM
Function delcared inline but not defined inline Nish C Programming 4 10-08-2004 03:31 PM
External inline functions calling internal inline functions Daniel Vallstrom C Programming 2 11-21-2003 01:57 PM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM



Advertisments