View Single Post
  #10 (permalink)  
Old April 25th, 2002
Pferdo Pferdo is offline
Devotee
 
Join Date: March 29th, 2002
Location: Germany
Posts: 21
Pferdo is flying high
Default performance is REALLY IMPORTANT...

...while using VB!

A professional C++ and VB programmer "B.Olaf" helped me to make faster routines, and now I finally know a bit more about RTLMoveMemory and the Memory in general... the routines listed below are 2 or even 3 times faster the my old ones: Use them!!!


<code>
Option Explicit
'Functions using 'RtlMoveMemory' by "B.Olaf Rasch" [bolaf-rasch@gmx.de]
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef lpvDest As Any, ByRef lpvSource As Any, ByVal cbCopy As Long)

Function EncodeNo16(ByVal Number As Long) As String
'"Long" is used to replace "unsigned int"
EncodeNo16 = Space(2)
CopyMemory ByVal EncodeNo16, Number, 2
End Function

Function DecodeNo16(ByVal Number As String) As Long
'"Long" is used to replace "unsigned int"
CopyMemory DecodeNo16, ByVal Number, 2
End Function

Function EncodeNo32(ByVal Number As Double) As String
Dim lngTemp As Long

If Number > 2147483647# Then
lngTemp = CLng(Number - CDbl(4294967296#))
Else
lngTemp = CLng(Number)
End If
EncodeNo32 = Space(4)
CopyMemory ByVal EncodeNo32, lngTemp, 4
End Function

Function DecodeNo32(ByVal Number As String) As Double
Dim lngTemp As Long

CopyMemory lngTemp, ByVal Number, 4
If lngTemp < 0 Then
DecodeNo32 = CDbl(4294967296#) + lngTemp
Else
DecodeNo32 = CDbl(lngTemp)
End If
End Function
</code>

thx!!!
Reply With Quote