I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

January Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Language Det...   Print This     
  From the September 2010 Issue of Prestwood eMag
 
Delphi Language Details:
Delphi Inlining (Inline)
 
Posted 11 years ago on 2/4/2009
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi Code Snippets Page
 Tags: Delphi , Inlining

KB101861

General Info: Inline Routines

Instead of calling a routine, you move the code from the routine itself and expand it in place of the call. In addition to manual inlining, some languages support automatic inlining where the compiler or some other pre-compiler decides when to inline a code routine. Also, some languages allow for developer defined inlining where the developer can suggest and/or force the inlining of a code routine. Inlining can optimize your code for speed by saving a call and return, and parameter management.

Languages Focus: Inlining

Does it support inlining? If so, does it support developer defined inlining? Does it support automatic inlining? Both?

Delphi Inlining

Delphi introduced developer defined function and procedure inlining with Delphi 2005. Use the inline keyword to tell the compiler to try to inline a routine (a compiler hint). Since Delphi will only try to inline the routine, make sure you test for speed because inlining a routine can lead to slower code under some circumstances.

Syntax Example:
function Add(a, b: Integer): Integer; inline;
begin
end;

More Info

Definition:  Inline Routines

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

Inlining is a great concept, and a potentially powerful optimization.  Before using it, though, be sure to read Delphi's help about Inline.

Delphi 2006, for example, help has some very explicit things to say about inline.  Among them:

  • The inline directive is a suggestion to the compiler. It won't necessarily be observed.
  • There are a number of cases in which inlining will not occur.
  • Inlining will not occur on any form of late-bound method.  This includes virtual, dynamic, and message methods.
  • Routines that are not defined before use cannot be inlined.
  • Routines  that take open array parameters cannot be inlined.
  • Procedures and functions used in conditional expressions in while-do and repeat-until cannot be expanded inline.

There are other limitations, so be sure to read Delphi help.

Posted 11 years ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1261A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Advanced

1 Advanced Level Question

Question #1: Multiple Choice

The correct syntax to inline a function is...

Answer:
1. 
function DoSomething; __forceinline;
begin
end;
2. 
function DoSomething; inline;
begin
end;
3. 
_inline function DoSomething;
begin
end;
4. 

All of the above.

5. 

None of the above. Delphi does not support inlining even in later versions of Delphi such as Delphi 2005 and above.


 KB Article #101861 Counter
16372
Since 2/4/2009

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech