FastStringSwap




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


Public Sub SwapStr(sSource As String, sDest As String)
'

' Using this routine is quicker than

'

' sTmp = sDest

' sDest = sSource

' sSource = sTmp

'

' By a factor of 12 for really long strings !!

'

Dim lSaveAddr As Long

' Save memory descriptor for sSource


lSaveAddr = StrPtr(sSource)

' Copy memory descriptor of sDest to sSource


CopyMemory ByVal VarPtr(sSource), ByVal VarPtr(sDest), 4

' Copy memory descriptor of sSource to sDest


CopyMemory ByVal VarPtr(sDest), lSaveAddr, 4

End Sub










( faststringswap.html )- by Paolo Puglisi - Modifica del 17/12/2023