tags:

views:

355

answers:

4

can any one please say what is use of inline keyword in delphi

+12  A: 

It is a hint to the compiler that the function/procedure should be (if possible) inlined, ie when you call it it should be expanded like a macro instead of being called.

This is an optimization for (very) small functions where the overhead of a call would be significant. You will find many examples in for example windows.pas

What actually happens depends on the complexity of the function, public/private access and your Delphi version.

Henk Holterman
+3  A: 

It tells the compiler to generate code for the inline; routine on the place where it is called, instead of jumping to the routine and back.

For procedures that translate to very short assembler, this can be a benefit to performance, because the actual code is relatively short compared to the calling and the procedure prologue/epilogue.

If the procedure is too long, it can be a brake on performance though, and blow up your code gigantically

Marco van de Voort
+7  A: 

Others have answered what inline does, but I just wanted to point out that there is a Compiler option to set inline on, off, or auto. Check out "Calling Procedures and Functions" in the D2009 docs for a very good explanation of the mechanics of inline. Here's the link to the online docs:

Delphi Online Docs for inline

MarkF
+1  A: 

It's borrowed from C in that it tells the compiler that this is a short routine that is frequently called and it recommends that the compiler treats the function as a macro and integrates the function code directly into the program at the point called rather than use a function call.

This gives faster code because there is no function call overhead, but at the expense of a larger program. Note too that like in C this is a recommendation to the compiler, it doesn't actually have to do so and the optimiser may override you.

Where to do this? Well like loop unwinding it's a technique that is very rarely of use nowadays. The classic place to use this is deep in a nested structure that is real-time critical, such as rendering code in a graphics application where a few machine calls shaved on each iteration can increase your screen refresh rate.

Cruachan