<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準則編譯邊學(xué)-F.3 如果函數(shù)非常小而且時間敏感,將其定義為i...

          2af92180c9094d03945aadeb20710057.webp

          F.5: If a function is very small and time-critical, declare it inline(如果函數(shù)非常小而且時間敏感,將其定義為inline)

          Reason(原因)

          Some optimizers are good at inlining without hints from the programmer, but don't rely on it. Measure! Over the last 40 years or so, we have been promised compilers that can inline better than humans without hints from humans. We are still waiting. Specifying inline encourages the compiler to do a better job.

          有些優(yōu)化程序擅長在程序員沒有提示的時候就行inline處理,但是不要依靠這一點。算一下!差不多有四十年左右了,我們被許諾編譯器可以在沒有得到任何提示的情況下可以比人進行更好的inline處理。我們還在等。還是定義inline以便讓編譯器更好地工作吧。

          Example(示例)
          inline string cat(const string& s, const string& s2) { return s + s2; }

          Exception(例外)

          Do not put an inline function in what is meant to be a stable interface unless you are certain that it will not change. An inline function is part of the ABI.

          不要將inline函數(shù)放進本來希望穩(wěn)定的接口中,除非你確定它不會改變。inline函數(shù)也是ABI的一部分。


          譯者注:inline可能會隨著實現(xiàn)方式的變化而隱式或顯示的發(fā)生變化。

          Note(注意)

          constexpr implies inline.

          constexpr也包含inline的意思。

          Note(注意)

          Member functions defined in-class are inline by default.

          類聲明中定義的函數(shù)默認是inline的。


          譯者注:關(guān)于inline函數(shù),在《effective C++》中有詳細的描述。

          Exception(例外)

          Template functions (incl. template member functions) are normally defined in headers and therefore inline.

          模板函數(shù)通常定義在頭文件中,因此也是inline。

          Enforcement(實施建議)

          Flag inline functions that are more than three statements and could have been declared out of line (such as class member functions).


          標記那些超過3條語句且應(yīng)該已經(jīng)單獨定義(例如類成員函數(shù))的inline函數(shù)。

          瀏覽 70
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美成人激情视频 | 天天天天天天色 | 亚洲成人做爱视频 | 一级a片在线 | 欧美精品三级在线观看 |