Re: copymemory basic question
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Wed, 31 Aug 2005 15:08:35 -0700
Hi Jim --
>> I might have an idea on speeding that up a bit...
>
> Just for completeness, there's a DxSwapStr function in Stamina --
> worth seeing how it stacks [cough] up against any VB versions.
<ahem>
Well... Yeah, that one pretty well blows away the immediate competition. Three
runs, VB5/SP3, EXE /w all opts:
Iterations: 1000000
Overhead: 2
StrSwap01: 381
StrSwap02: 122
StrSwap03: 122
StrSwap04: 127
DxSwapStr: 90
Iterations: 1000000
Overhead: 3
StrSwap01: 380
StrSwap02: 125
StrSwap03: 124
StrSwap04: 120
DxSwapStr: 91
Iterations: 1000000
Overhead: 1
StrSwap01: 393
StrSwap02: 121
StrSwap03: 124
StrSwap04: 121
DxSwapStr: 92
Using:
Public Sub StrSwap01(s1 As String, s2 As String)
Dim tmp As String
' Traditional method using pure VB.
tmp = s1
s1 = s2
s2 = tmp
End Sub
Public Sub StrSwap02(s1 As String, s2 As String)
Static lpTmp As Long
' Basic CopyMemory method that swaps pointers, using
' a Static variable for temporary holding space.
lpTmp = StrPtr(s1)
Call CopyMemory(ByVal VarPtr(s1), ByVal VarPtr(s2), 4&)
Call CopyMemory(ByVal VarPtr(s2), lpTmp, 4&)
End Sub
Public Sub StrSwap03(s1 As String, s2 As String)
Dim lpTmp As Long
' Basic CopyMemory method that swaps pointers, using
' a standard variable for temporary holding space.
lpTmp = StrPtr(s1)
Call CopyMemory(ByVal VarPtr(s1), ByVal VarPtr(s2), 4&)
Call CopyMemory(ByVal VarPtr(s2), lpTmp, 4&)
End Sub
Public Sub StrSwap04(s1 As String, s2 As String)
Dim ptrStr1 As Long
Dim ptrVar2 As Long
' Enhanced CopyMemory removes one VarPtr call, and
' doesn't use Static vars for pointers.
ptrStr1 = StrPtr(s1)
ptrVar2 = VarPtr(s2)
CopyMemory ByVal VarPtr(s1), ByVal ptrVar2, 4&
CopyMemory ByVal ptrVar2, ptrStr1, 4&
End Sub
I'll see what else I can cook up. <g>
Thanks... Karl
--
Working Without a .NET?
http://classicvb.org/petition
.
- Follow-Ups:
- Re: copymemory basic question
- From: Jim Mack
- Re: copymemory basic question
- References:
- Re: copymemory basic question
- From: Karl E. Peterson
- Re: copymemory basic question
- From: Donald Lessau
- Re: copymemory basic question
- From: Jim Mack
- Re: copymemory basic question
- From: Donald Lessau
- Re: copymemory basic question
- From: Karl E. Peterson
- Re: copymemory basic question
- From: Jim Mack
- Re: copymemory basic question
- Prev by Date: Re: copymemory basic question
- Next by Date: Re: copymemory basic question
- Previous by thread: Re: copymemory basic question
- Next by thread: Re: copymemory basic question
- Index(es):
Relevant Pages
|