Page 2 of 2 FirstFirst 12
Results 41 to 46 of 46

Thread: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6

  1. #41

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Posts
    536

    Re: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6

    Quote Originally Posted by DEXWERX View Post
    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

  2. #42
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,229

    Re: [RESOLVED] Clearing array is fast in VB5 but very slow in VB6

    Quote Originally Posted by Karl77 View Post
    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.

  3. #43
    Lively Member
    Join Date
    Jun 2016
    Posts
    109

    Unhappy Re: Clearing array is fast in VB5 but very slow in VB6

    Quote Originally Posted by Elroy View Post

    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:

    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:

    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

  4. #44
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,169

    Re: Clearing array is fast in VB5 but very slow in VB6

    Quote Originally Posted by tubus View Post
    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>

  5. #45
    Lively Member
    Join Date
    Jun 2016
    Posts
    109

    Re: Clearing array is fast in VB5 but very slow in VB6

    Quote Originally Posted by wqweto View Post
    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.

  6. #46
    New Member
    Join Date
    Apr 2024
    Location
    London
    Posts
    6

    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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width