### Tips for Inlining

- For most applications, the most effective value for auto-inlining is between 5 and 25. The value required to inline a specific function may be slightly larger when /O+ is specified than when /O- is specified.
- Because auto-inlining looks only at the number of ACUs for a function, the functions that are inlined are not always the best candidates for inlining.
- When you turn inlining on, very small static functions that are not called frequently may also be inlined. For this type of function, there is always greater benefit in inlining.
- When you use inlining, you need more stack space. When a function is called, its local storage is allocated at the time of the call and freed when it returns to the calling function. If the same function is inlined, storage is allocated when the function that calls it is entered, and is not freed until the calling function ends.
- Inlining can also result in slower program performance, especially if you use auto-inlining. As much as possible, use the _Inline or inline keyword to choose the functions to be inlined.
- If you have a function that is called many times from a few functions, but infrequently from others, create a copy of the function with a different name and inline it only in the functions that call it often. Turn optimization on.
- Wherever possible, use constant arguments. Opportunities for optimization are greater. For example, given the following function:

         void glen(int a, int b)
         {
            if (a == 10)
            {
               switch(b)
               {
                  case 1:  .
                           :
                  case 20: puts("b is 20");
                           break;
                  case 30: .
                           :
                  default: .
                           :
               }
            }
         }

  and assuming your program calls glen several times with constant arguments, for example, glen(10, 20);, each call to glen causes the if and switch expressions to be evaluated. If glen is inlined, the compiler can then optimize the function. The evaluation of the if and switch statements can be done at compile time, and the function code can then be reduced to only the puts statement from case 20.

Inlining

Restrictions on Inlining
Benefits and Drawbacks of Inlining