Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will declaration of array outside a function increase the performance of repeatedly calls to the function?

function MyFunc(const Value: Integer): Integer;
const
  MyArray: array[0..255] of Byte = ( ... ); // values of the array here

begin
  ... // Some codes here
  Result := Integer(MyArray[Value shr 58]);
end;

Will declare MyArray outside MyFunc increases the performance of repeatedly calls to MyFunc?

like image 510
Aeoliyan Avatar asked Sep 09 '15 09:09

Aeoliyan


1 Answers

Will declare MyArray outside MyFunc increases the performance of repeatedly calls to MyFunc?

No. The compiler will produce identical code no matter if MyArray is local to the function, or a constant at a wider scope. Typed constants are stored in the data segment of the executable, irrespective of their scope.

like image 88
David Heffernan Avatar answered Nov 15 '22 06:11

David Heffernan