简体   繁体   中英

What if i use inline function here and there

I know that inline functions are used so that we can be rid of function calls.

I see that using inline function is a good way of using the storage and keeping the stack more empty.

Is it a good programming practice to use inline functions everywhere.

I think so, because since compilers are not obligated to use inline functions as inline when the functions are complex, so would it be a nice approach to append that little word inline to every functions?

My general rule is to use inline functions when the content of the function is less than or equal to the overhead of calling the function.

An example is a getter or setter method.

After the program works correctly and robustly, I convert some functions in the bottleneck sections to use inline . However, this is a micro-optimization and usually doesn't generate as much savings as redesigning an algorithm.

As others have stated, inline functions wreak havoc on the build process because a header file is changed and all dependencies on the header file must be rebuilt. A non-inlined function would only require building of a single translation unit.

inline is only a hint to the compiler to inline the function. Compilers can also inline other functions you didn't mark as inline when optimizing. The problem with making every function inline, is the whole function will need to be in a header so that it can be called from multiple source files. This will increase compile times. My advice is to forget the inline keyword exists, until you have a real performance issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM