I have a routine that adds ordinal elements ("Day" or "Night" enumerated type) to a multi-dimensional dynamic array, which is declared as:
TShiftType = (stDay, stNight);
TScheduleArray = array of array of array [1..DaysPerWeek] of TShiftType;
The array could contain anything between 1 element (e.g. (Day, Day, Day, Day, Day, Night, Night)
) and over 20,000 elements. Each element may itself have sub-elements depending on how many weeks are being processed.
So one element in a two-week array could look like:
((stDay, stDay, stDay, stDay, stDay, stNight, stNight), (stDay, stDay, stDay, stDay, stDay, stNight, stNight))
This runs extremely fast and works very well when the number of elements is relatively low (about under 1000). Once the number of weeks and elements increases, just adding a new element to the array (after calling SetLength
to increase the length of the array by one) starts to slow down exponentially.
Sometimes I also get an Access Violation. When I use the "Find Error" facility in Delphi, it takes me to the @DynArrayAsg
method in the CPU window. But I never get the EOutOfMemory
exception that the Delphi help says I would get if not enough memory was available to reallocate the variable.
Is this slowing down of access to memory expected behaviour? I am using Delphi 6.