Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə147/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   143   144   145   146   147   148   149   150   ...   294
DelphiLanguageGuide

Using the inline Directive
The Delphi compiler allows functions and procedures to be tagged with the inline directive to improve performance.
If the function or procedure meets certain criteria, the compiler will insert code directly, rather than generating a call.
Inlining is a performance optimization that can result in faster code, but at the expense of space. Inlining always
causes the compiler to produce a larger binary file. The inline directive is used in function and procedure declarations
and definitions, like other directives.
procedure MyProc(x:Integer); inline;
begin
    // ...
end;
function MyFunc(y:Char) : String; inline;
begin 
   // ..
end;
The inline directive is a suggestion to the compiler. There is no guarantee the compiler will inline a particular routine,
as there are a number of circumstances where inlining cannot be done. The following list shows the conditions under
which inlining does or does not occur:
Inlining will not occur on any form of late-bound method. This includes virtual, dynamic, and message methods.
Routines containing assembly code will not be inlined.
Constructors and destructors will not be inlined.
The main program block, unit initialization, and unit finalization blocks cannot be inlined.
Routines that take open array parameters cannot be inlined.
Code can be inlined within packages, however, inlining never occurs across package boundaries.
No inlining will be done between units that are circularly dependent. This included indirect circular dependencies,
for example, unit A uses unit B, and unit B uses unit C which in turn uses unit A. In this example, when compiling
unit A, no code from unit B or unit C will be inlined in unit A.
The compiler can inline code when a unit is in a circular dependency, as long as the code to be inlined comes
from a unit outside the circular relationship. In the above example, if unit A also used unit D, code from unit D
could be inlined in A, since it is not involved in the circular dependency.
129


If a routine is defined in the interface section and it accesses symbols defined in the implementation section,
that routine cannot be inlined.
Routines in classes cannot be inlined if they access members with less (i.e. more restricted) visibility than the
method itself. For example, if a public method accesses private symbols, it cannot be inlined.
If a routine marked with inline uses external symbols from other units, all of those units must be listed in the
uses statement, otherwise the routine cannot be inlined.
Procedures and functions used in conditional expressions in while-do and repeat-until statements cannot be
expanded inline.
If you modify the implementation of an inlined routine, you will cause all units that use that function to be recompiled.
This is different from traditional rebuild rules, where rebuilds were triggered only by changes in the interface section
of a unit.
The 
{$INLINE}
 compiler directive gives you finer control over inlining. The 
{$INLINE}
 directive can be used at
the site of the inlined routine's definition, as well as at the call site. Below are the possible values and their meaning:

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   143   144   145   146   147   148   149   150   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin