Inline functions and performance

Discussion in 'C++' started by Per, Nov 10, 2004.

  1. Per

    Per Guest

    Hi
    I am currently working on a mathlib and I want maximum performance
    (speed). If I delcare a function in the mathlib inline will the user
    apps take advantage of that or will it be called as regular function?
    So will a inline function from a lib file really be inline when I use
    it in different apps. ?
    /p
    Per, Nov 10, 2004
    #1
    1. Advertising

  2. Per

    Jonan Guest

    If you want to make it as a separate binary library - (.lib, .dll, .so, .a,
    etc.) exported function could _not_ be inline - truly - they are located in
    binary file not in your executable code.
    If you want inline functions consider writing something line STL - i.e.
    header files which will compile every time they're used - this way you'll
    have inline functions.
    But before all that - try using GMP. (Gnu MultiPrecision library).
    -Jonan

    "Per" <> wrote in message
    news:...
    > Hi
    > I am currently working on a mathlib and I want maximum performance
    > (speed). If I delcare a function in the mathlib inline will the user
    > apps take advantage of that or will it be called as regular function?
    > So will a inline function from a lib file really be inline when I use
    > it in different apps. ?
    > /p
    Jonan, Nov 10, 2004
    #2
    1. Advertising

  3. Per

    angelo Guest

    Per wrote:
    > Hi
    > I am currently working on a mathlib and I want maximum performance
    > (speed). If I delcare a function in the mathlib inline will the user
    > apps take advantage of that or will it be called as regular function?
    > So will a inline function from a lib file really be inline when I use
    > it in different apps. ?
    > /p

    No, to have a function inlined, its definition(the source code, not just
    the lib file) must be included where it is used.
    Just think that, to make a function inlined, you have to have its code
    expanded in the program. With only the lib, the compiler has no way of
    expanding the function.
    angelo, Nov 10, 2004
    #3
  4. Per

    Lionel B Guest

    Per wrote:
    > Hi
    > I am currently working on a mathlib and I want maximum performance
    > (speed). If I delcare a function in the mathlib inline will the user
    > apps take advantage of that or will it be called as regular function?
    > So will a inline function from a lib file really be inline when I use
    > it in different apps. ?
    > /p


    As far as I know, whether your code is in a library or not has no
    bearing on whether a function is inlined or not (the C++ standard has
    nothing to say about this - it does not cocern itself with libraries or
    linkage issues in general).

    You should, however, be aware that to declare a function inline (either
    implicitly - if it is a member function - by defining it in the class
    declaration, or explicitly with the keyword `inline') is generally a
    "hint", rather than a hard-and-fast directive to the compiler.
    Ultimately (and this will depend on your particular compiler,
    optimisation flags, etc.) your compiler may or may not actually inline
    any given function declared as such.

    Regards,

    --
    Lionel B
    Lionel B, Nov 10, 2004
    #4
  5. Per

    Lionel B Guest

    Lionel B wrote:
    > Per wrote:
    > > Hi
    > > I am currently working on a mathlib and I want maximum
    > > performance (speed). If I delcare a function in the mathlib
    > > inline will the user apps take advantage of that or will it
    > > be called as regular function? So will a inline function from
    > > a lib file really be inline when I use it in different apps. ?

    >
    > As far as I know, whether your code is in a library or not has
    > no bearing on whether a function is inlined or not (the C++ standard
    > has nothing to say about this - it does not cocern itself with
    > libraries or linkage issues in general).


    Correction: as other posters have pointed out, if your library code
    really resides in a separate module, it could not truly be inlined.
    However, for a program to have access to your (library) function, it is
    customary to include a header file containing a declaration for that
    function. Generally, if a function is to be inlined, its *definition*
    would reside in - or at least be included in - the same (header) file
    as the declaration. Under which scenario your function might well be
    inlined, with the caveat below:

    > You should, however, be aware that to declare a function inline
    > (either implicitly - if it is a member function - by defining it in
    > the class declaration, or explicitly with the keyword `inline') is
    > generally a "hint", rather than a hard-and-fast directive to the
    > compiler. Ultimately (and this will depend on your particular
    > compiler, optimisation flags, etc.) your compiler may or may not
    > actually inline any given function declared as such.

    Regards,

    --
    Lionel B
    Lionel B, Nov 10, 2004
    #5
  6. Per

    Per Guest

    "Lionel B" <> wrote in message news:<>...
    > Lionel B wrote:
    > > Per wrote:
    > > > Hi
    > > > I am currently working on a mathlib and I want maximum
    > > > performance (speed). If I delcare a function in the mathlib
    > > > inline will the user apps take advantage of that or will it
    > > > be called as regular function? So will a inline function from
    > > > a lib file really be inline when I use it in different apps. ?

    > >
    > > As far as I know, whether your code is in a library or not has
    > > no bearing on whether a function is inlined or not (the C++ standard
    > > has nothing to say about this - it does not cocern itself with
    > > libraries or linkage issues in general).

    >
    > Correction: as other posters have pointed out, if your library code
    > really resides in a separate module, it could not truly be inlined.
    > However, for a program to have access to your (library) function, it is
    > customary to include a header file containing a declaration for that
    > function. Generally, if a function is to be inlined, its *definition*
    > would reside in - or at least be included in - the same (header) file
    > as the declaration. Under which scenario your function might well be
    > inlined, with the caveat below:
    >
    > > You should, however, be aware that to declare a function inline
    > > (either implicitly - if it is a member function - by defining it in
    > > the class declaration, or explicitly with the keyword `inline') is
    > > generally a "hint", rather than a hard-and-fast directive to the
    > > compiler. Ultimately (and this will depend on your particular
    > > compiler, optimisation flags, etc.) your compiler may or may not
    > > actually inline any given function declared as such.

    > Regards,



    So, I have so far written a bunch of classes and functions compiled to
    a lib file and link it staticly. How do you suggest I design my "math
    package" so it can be used easliy in different project. Like STL...
    I don't want to add all my classes to the workspace and stuff like
    that =)
    /p
    Per, Nov 12, 2004
    #6
    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. Replies:
    3
    Views:
    456
  2. Daniel Vallstrom
    Replies:
    2
    Views:
    1,860
    Kevin Bracey
    Nov 21, 2003
  3. jamihuq

    converting inline functions to C functions

    jamihuq, May 16, 2006, in forum: C Programming
    Replies:
    7
    Views:
    342
  4. Sean
    Replies:
    4
    Views:
    665
    Rolf Magnus
    Apr 30, 2006
  5. Rahul
    Replies:
    3
    Views:
    452
    James Kanze
    Feb 28, 2008
Loading...

Share This Page