Inlining is optional optimization. The compiler is not obliged to inline a function.
1 2 3 4 5 6 7 8 9 10 11
|
int foo(int x)
{
// foo code
}
int bar()
{
// code
y = foo(z);
// code
}
|
The unoptimized version has foo's binary code as clearly separate block and the bar's binary code contains instructions of a
function call.
If the foo() can be inlined, then bar() won't have a function call, but foo's code directly injected.
Obviously, if the compiler of bar cannot see foo's code (if implementation of foo is not in the same translation unit as bar's implementation), then it cannot inline.
An advanced linker might do optimizations across transaltion units. At least one C++ toolset can use profiling information from a run of the program to improve optimization on the next compilation of the program.
PhysicsIsFun wrote: |
---|
Ok, I put the structure definition now in a separate header file and #included it in every .cpp file.
In my other headers, I simply declared structure particle; instead of #including particle.h, because the headers only need a declaration, no definition. This should be best, right? |
Yes, in most cases.
More on that:
https://herbsutter.com/2013/08/19/gotw-7a-solution-minimizing-compile-time-dependencies-part-1/
and on tangent:
https://www.bfilipek.com/2018/01/pimpl.html
https://herbsutter.com/gotw/_100/
https://herbsutter.com/gotw/_101/
Parallelization can occur on many forms and levels:
* Auto-vectorization. CPU can perform multiple math operations with single instruction. SIMD. The MMX/SSE*/AVX* instruction sets. Compiler can do this for you, if requested.
* Threads
* GPGPU
* Multiple processes, possibly in separate computers, for example with MPI
You can even have all of them in use in same application.
gets called thousands of times |
How much processing time does that use? What fraction of all the time of the application's run? Have you profiled your program to show that the function is the biggest consumer?