What Does It Mean For a C++ Function To Be Inline?

后端 未结 9 782
攒了一身酷
攒了一身酷 2020-12-01 06:12

See title: what does it mean for a C++ function to be inline?

9条回答
  •  一生所求
    2020-12-01 06:56

    Inline functions alter the performance profile of your application by possibly generating instructions that are placed in the code segment of your application. Whether a function is inlined is at the discretion of your compiler. In my experience, most modern compilers are good at determining when to comply with a user's request to inline.

    In many cases, inlining a function will improve its performance. There is an inherent overhead to function calls. There are reasons, however, why inlining a function could be negative:

    • Increasing the size of the binary executable by duplicating code could lead to disk thrashing, slowing your application down.
    • Inlining code could contribute to cache misses, or possibly contribute to cache hits depending on your architecture.

    The C++ FAQ does a good job of explaining the intricacies of the keyword: http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.3

提交回复
热议问题