Search code examples
performancedelphimemorydelphi-7delphi-xe

Is there a real performance gain when I turn {$IMPORTEDDATA} off?


Is there a real performance gain when I turn {$IMPORTEDDATA} off ?

The manual only says this: "The {$G-} directive disables creation of imported data references. Using {$G-} increases memory-access efficiency, but prevents a packaged unit where it occurs from referencing variables in other packages."


Update:

Here is more info I could find:

"The Debugging section has the new option Use imported data references (mapped to $G), which controls the creation of imported data references (increasing memory efficiency but preventing the access of global variables defined in other runtime packages)"


Solution

  • Almost never

    This directive only refers to accessing global unit variables from another unit.

    If you use {$G+}

    unit1;
    
    interface
    
    var
      Global1: integer;   //<--  this is a global var in unit1.
      Form1: TForm1;      //<--  also a global var, but really a pointer
    

    Global1 will be accessed indirectly via a pointer (if and when accessed from outside unit1)
    Form1 will also be accessed indirectly (i.e. change from a direct pointer to an indirect pointer).

    if you use {$G-}, the access to integer global will be direct and thus slightly faster.

    This will only make a difference if you use global public unit variables in another unit and in time critical code, i.e. almost never.

    See this article: http://hallvards.blogspot.com/2006/09/hack13-access-globals-faster.html