I am using Delphi XE2 and I have to write a function which needs some constant arrays. If I declare these inside the function, when will they be created? Each time when the function runs or only once?
Example:
function Something;
const
Arr: array[0..100] of string = ('string1', 'string2'...);
begin
end;
CodePudding user response:
The array will occupy a fixed, constant, region in your process's memory for the duration of the process's life.
In fact, you can easily see that yourself:
Each time the timer fires, you'll find that Pointer(@Arr)
has the same value, and at that point in memory, you'll find your constant array.
And if you change it using the Memory panel (like string1
to orange1
), the change will persist.