Inline functions and performance

P

Per

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
 
J

Jonan

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
 
A

angelo

Per said:
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.
 
L

Lionel B

Per said:
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,
 
L

Lionel B

Lionel said:
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,
 
P

Per

Lionel B said:
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:

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top