In my graphic program 3D arrays manipulations are everywhere. This is normally done with for-next loops since the data has to be manipulated. Just duplicating an array is rare and mainly for backup/restore of a graphic. Nevertheless speed is important and I did some speed test for a 3x1920x1080 array of single:
1000 repeats:
Method 1 (for-do): 19 seconds
Method 2 (for-do +copy): 5 seconds
Method 3 (setlength): 29 seconds
Method 4 (1D array): 8 seconds
My conclusion is that method 2 is the best method. Using setlength is a disappointing slow process. Method 1 is required for array/graphic manipulations.
For method 4 you have to add later multiplications to access the data correctly which will slow down it significantly e.g.:
for k:=0 to nrcolors-1 do
for i:=0 to width2-1 do
for j:=0 to height-1 do
F[k+nrcolors*i+nrcolors*width2*j]:=E[k+nrcolors*i+nrcolors*width2*j];
The 4 methods:
{copy contains method 1}
for k:=0 to nrcolors-1 do
for i:=0 to width2-1 do
for j:=0 to height-1 do
D[k,i,j]:=C[k,i,j];
{copy contains method 2}
for k:=0 to nrcolors-1 do
for i:=0 to width2-1 do
D[k,i]:=copy(C[k,i],0,height2);
{copy contains method 3}
D:=C;{copy pointer}
setlength(D,nrcolors,width2,height2);{make real duplicate}
{copy contains method 4}
for k:=0 to (nrcolors-1)*(width2-1)*(height2-1) do
F[k]:=E[k];