Re: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6
Quote:
Originally Posted by
DEXWERX
This could all be fixed if MS would Open Source VB.
Not sure if Open Source is a good idea.
Think of the many different runtimes it could produce...
...on the other hand, I don't have a better idea.
I would prefer to get a new VB6+ from a company, at best MS.
Karl
Re: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6
Quote:
Originally Posted by
Karl77
Not sure if Open Source is a good idea.
Think of the many different runtimes it could produce...
...on the other hand, I don't have a better idea.
I would prefer to get a new VB6+ from a company, at best MS.
Karl
right, cause then we would have the same mess as all the C++ and .NET developers. ;)
Despite my sarcasm - I'm not actually disagreeing.
If I were still using C++ primarily - I would go to great lengths to use the c runtime the OS uses.
Re: Clearing array is fast in VB5 but very slow in VB6
Quote:
Originally Posted by
Elroy
Code:
Option Explicit
'
Private Declare Function PerformCount Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Any) As Long
Private Declare Function PerformFreq Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Any) As Long
'
Private Sub Form_Load()
Dim timeFreq As Currency
Dim startTime As Currency
Dim endTime As Currency
Dim i As Long
Dim a() As Variant
PerformFreq timeFreq
ReDim a(1 To 1000)
For i = LBound(a) To UBound(a)
Set a(i) = New Class1
Next i
'
PerformCount startTime
ReDim Preserve a(LBound(a) To LBound(a))
PerformCount endTime
MsgBox "Nanoseconds: " & Format$((endTime - startTime) / timeFreq * 1000000000, "0.000")
ReDim a(1 To 1000)
For i = LBound(a) To UBound(a)
Set a(i) = New Class1
Next i
'
PerformCount startTime
For i = LBound(a) To UBound(a) - 1
ReDim Preserve a(LBound(a) To UBound(a) - 1)
Next
PerformCount endTime
MsgBox "Nanoseconds: " & Format$((endTime - startTime) / timeFreq * 1000000000, "0.000")
ReDim a(1 To 1000)
For i = LBound(a) To UBound(a)
Set a(i) = New Class1
Next i
'
PerformCount startTime
Erase a
ReDim a(1 To 1)
Set a(1) = New Class1
PerformCount endTime
MsgBox "Nanoseconds: " & Format$((endTime - startTime) / timeFreq * 1000000000, "0.000")
Unload Me
End Sub
.....
Just in case someone ends up here in search of high precision timestamps
ATTENTION!
The lines:
Quote:
Private Declare Function PerformCount Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Any) As Long
Private Declare Function PerformFreq Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Any) As Long
should be:
Quote:
Private Declare Function PerformCount Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Any) As Long
Private Declare Function PerformFreq Lib "kernel32" Alias "QueryPerformanceFrequency" (lpPerformanceCount As Any) As Long
Took me a while to see that!
And the timing resolution on my machine (W8.1) seems to be ~300 nanosecs, so it makes not much sense to display intervals smaller than that.
Another strange thing:
if you use LONG instead of CURRENCY, then the first call of PerformCount changes the value of the previously with PerformFreq assigned timeFreq
How on earth could this be ???
Thanks to Elroy for putting me on the right track and Happy New Year to all :cool:
Re: Clearing array is fast in VB5 but very slow in VB6
Quote:
Originally Posted by
tubus
if you use LONG instead of CURRENCY, then the first call of PerformCount changes the value of the previously with PerformFreq assigned timeFreq
How on earth could this be ???
Stack layout.
Local variables are allocated on the stack and Long variables are 4 bytes each while Currency variables are 8 bytes.
Passing the address of the first Long var to an API that outputs 8 bytes at this address effectively overwrites the second Long var.
cheers,
</wqw>
Re: Clearing array is fast in VB5 but very slow in VB6
Quote:
Originally Posted by
wqweto
Stack layout.
Local variables are allocated on the stack and Long variables are 4 bytes each while Currency variables are 8 bytes.
Passing the address of the first Long var to an API that outputs 8 bytes at this address effectively overwrites the second Long var.
cheers,
</wqw>
...aha, thanks!
Time to learn something new every day. :thumb:
Re: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6
For archive purposes and for anyone interested, here's a detailed explanation of what is going on: Faster VB6 / VBA class deallocation