Inlining

 
Chapter 3 - Object-Oriented C#
bySimon Robinsonet al.
Wrox Press 2002
  

Some developers may worry that, in the above sections, we have presented a number of situations in which standard C# coding practices have led to very small functions - for example accessing a field via a property instead of directly, and having one overload of a method call another overload. In this kind of situation, C++ developers in particular will be accustomed to using the C++ inline keyword to request that small methods be inlined ( replaced by inline code during compilation) in order to remove the excess method call (with all the associated overhead of adding and removing parameters and return address to/from the stack) - but C# does not have an inline or equivalent keyword. There is nevertheless no need to worry about performance loss from these kinds of programming methodologies in C#. Recall that C# code is compiled to IL then JIT-normally compiled at runtime to native executable code. Well the JIT compiler is designed to generate highly optimized code. Although it is not in general possible to predict what methods will be inlined in particular circumstances, experience has shown that the JIT compiler is ruthless when it comes to inlining any function calls that look suitable. A method or property whose implementation simply calls another method or returns a field will almost certainly be inlined.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net