Ads Top

Tips to Copy Large Arrays Faster

You can copy arrays much faster with a simple API call:

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (Dest As Any, _
Source As Any, ByVal Length As Long)

Private Sub CopyArray()
Dim lngbytes As Long
Dim lngSrc(1 To 600000) As Long
Dim lngDest(1 To 600000) As Long

'
' Number of bytes equals number of array
' elements times the element length.
' by. Kerja Keras Adalah Energi Kita.


lngbytes = (UBound(lngSrc) - LBound(lngSrc) + 1) * Len(lngSrc(1))
'
' Copy the array passing the address of the start to
' the destination and source arrays and the length
' of the arrays.
'
Call CopyMemory(lngDest(LBound(lngDest)), lngSrc(LBound(lngSrc)), lngbytes)
End Sub

3 comments:

virtue said...

how about resource memory?

conradsharry said...

CopyMemory copies a series of bytes from one location in the computer's memory to another. CopyMemory function can be used to transfer data between any kinds of variables, arrays, data structures, or even abstract memory addresses, to use arrays, reference the first element of the array. Normally, the 'Dest' and 'Source' parameters are the variables or whatever objects' memory locations to copy to/from. If you want to use either a string variable or have a Long-type variable that identifies a different memory address (i.e., the variable acts as a pointer), the ByVal keyword must be used in front of the parameter.This functions does not return a value.

Anonymous said...

nice info man:)

Powered by Blogger.