G
GJ
The performance can be DEGRADED by making a function "inline". Is it TRUE in
any case ?
any case ?
GJ said:The performance can be DEGRADED by making a function "inline". Is it TRUE
in any case ?
When I mean what scenario ?Rolf Magnus said:Yes.
Is that the same story on template code, where the implementation isRolf said:Yes.
GJ said:When I mean what scenario ?
resident in a .hh file (or a .h file).
class whatever {
public:
template<typename T>
void some_method(T& var) {}
};
If memory serves though, I think implementations in a header file is
already inlined?
They are, in fact, candidate for inlining. There are lots of functions
that are simply impossible to be inlined.
Rolf said:If the function gets called from many places, too much inlining can increase
code size significantly, which will lower the cache efficiency on systems
that do use caching (which is the majority these days).
On modern workstation-like computers,
the cache is extremely important for fast code execution.
Reading a value from RAM can take several hundred clock cycles.
Similarly, if there is conditional code or a loop in the inline function,
the branch prediction unit gets stressed more.
Unfortunatly, this is not an effect that you can simply measure on a per
function basis to find out whether inlining it is faster or not.
It's more like a tendency, and it likely depends on the CPU model,
even for different CPUs of the same architecture.
Is that the same story on template code, where the implementation is
resident in a .hh file (or a .h file).
class whatever {
public:
template<typename T>
void some_method(T& var) {}
};
If memory serves though, I think implementations in a header file is
already inlined?
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.