Should I use `inline` for heavily used functions?

I have a class cnVectorthat represents a point in three-dimensional space. Its + - * / operators are heavily used.
Their implementation is very short:

cnVector cnVector::operator + (const cnVector& v) const {
    return cnVector(
        x + v.x,
        y + v.y,
        z + v.z );
}

My question is that this function is very short, should it be built into it, although its intensive use? or will it generate too much code when using it?

+5
source share
5 answers

Yes, you probably should. A good option for using the inline keyword in C ++ is: small functions that are heavily used.

See also http://msdn.microsoft.com/en-us/library/1w2887zk%28v=vs.80%29.aspx

+5

, inline , . , , . , .

+5

inline , , . , , , . ( .)

inline , , , , .

+3

, .

, , , , , , , .

+2

If in doubt, compile it with the built-in and without it and compare the speed and size of the run. The compiler usually offers a switch for profiling as mentioned above to find out that the cost of a function call, measured over time,

+1
source

All Articles