From Delphi 2007, it is possible to use the keyword inline (similar as C++) to explicitly tell the compiler to inline a function or a procedure. For example, with the inline keyword, the following code will be compiled in Delphi XE3 with expanding the content of the test.
program Project; {$APPTYPE CONSOLE} {$R *.res} function test(a, b: integer): integer; inline; begin Result := a + b; end; begin writeln(test(1,2)); Readln; end.
If the inline (at then end of the function declaration) is missing, the compiler will keep the assembly call to function test without expanding the function, which will incur overhead of function call. This is not good for small functions, especially for functions that take size up to 32 bytes. By inlining the small functions, we have a better performance.
The delphi has a compiler directive {$INLINE} which takes three possible settings, ON/OFF/AUTO. For example, {$INLINE ON} is the default, we does not inline any functions unless a inline is specified. The {$INLINE OFF} tells the compiler not to inline any functions even there are inline keywords put at the end of functions. The {$INLINE AUTO} tells the compiler to inline any functions that are suitable, e.g. small functions. Besides, {$INLINE AUTO} will behave like {$INLINE ON} to inline functions that have inline keyword. Therefore, it is recommended to use {$INLINE AUTO} for code optimization purposes.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Get Started: Unicode in Delphi XE3
Next Post: Trick: Count the Number of API in COM