Initialization of local variables results in large executable sizes and long compile times
refer to the following code:
{$APPTYPE CONSOLE}
{$TYPEDADDRESS ON}
{$LONGSTRINGS OFF}
{$WRITEABLECONST OFF}
{ comment this define out to observe the large difference in compile time }
{$define initlargevar}
program LargeInitialization;
type
TRANGE = 0..(1024 * 1024) - 1;
TRECORD = record
count : int32;
elements : array[TRANGE]
of record
FieldA : int32;
FieldB : int32;
end;
end;
function main() : boolean;
var
LargeVar : TRECORD {$ifdef initlargevar} = () {$endif} ;
begin
result := FALSE;
LargeVar.count := LargeVar.count; { just do something }
result := TRUE;
end;
begin
main();
end.
when that code is compiled, it produces an 8 MB executable because the compiler instead of generating the 3 assembly instructions it takes to initialize the "LargeVar", it creates an 8 MB "private" variable in the initialized data segment which it then copies into the local.
The compiler should simply generate the few assembly instructions it takes to initialize the variable.