Copy an Array Faster, Redux

Copy an Array Faster, Redux

Simple is usually best. VB4 introduced direct assignment to Byte arrays, and VB5 later expanded that capability to include other array types as well.

This code does the same thing as the previous tip, with the same performance improvement:

 Dim IntArray1() As IntegerDim IntArray2() As IntegerReDim IntArray1(1 To 6000000)ReDim IntArray2(1 To 6000000)IntArray2 = IntArray1

As the old saying goes: “Keep it simple, stupid.” The previous tip is still useful for copying portions of arrays, but use direct assignment if you need to copy the entire array.


Share the Post: