Advertisement
Java_Volume1 String Manipulation #97299

Swap Variables 12 times Faster!

Swap Variable1 for Variable2 using API, this is usefull for creating data processing programs with many stored variables. See Info below

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Sub SwapStr(Var1 As String, Var2 As String)
' This is particularly useful in programs with lots of
' data analysis. Easily edited for any variant data
' manipulating. I'm currently using this coding and
' some vector codes to update my ThreeD Render Engine
' (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=8426)
' a little advertising on my part =)...
' Using this routine is faster than
  ' sTmp = Var1
  ' Var1 = Var2
  ' Var2 = sTmp
' By a factor up 12 for really long values !!
Dim lSaveAddr As Long
  
' Save memory descriptor location for Var1
lSaveAddr = StrPtr(Var1)
  
' Copy memory descriptor of Var2 to Var1
CopyMemory ByVal VarPtr(Var1), ByVal VarPtr(Var2), 4
' Copy memory descriptor of saved Var1 to Var2
CopyMemory ByVal VarPtr(Var2), lSaveAddr, 4
'4 bytes is the size of one string. You may need to
'edit this coding a little in order to create memory
'efficient storage for different data types (i.e.
'user defined types).
End Sub
Upload
Original Comments (3)
Recovered from Wayback Machine