Results 1 to 13 of 13

Thread: Fast clear an array

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    63

    Fast clear an array

    HI, guys!

    I have one question:
    Code:
    Private Type udtCell
        nAlignment As Integer
        nFormat As Integer
        nFlags As Integer
        sValue As String
        sTag As String
        lCellData As Long
        pPic As StdPicture
        IsSized As Boolean
    End Type
    Private Type udtItem
        lHeight As Long
        lImage As Long
        lItemData As Long
        nFlags As Integer
        sTag As String
        bGroupRow As Boolean
        bVisible As Boolean
        Cell() As udtCell
    End Type
    Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (ByRef Destination As Any, ByVal Length As Long)
    
    Private Sub Command1_Click()
        Dim x() As udtItem, y() As udtItem, z() As udtItem, I As Long, L As Long
        For I = 0 To 100000
            ReDim Preserve x(I) As udtItem
            x(I).bVisible = True
            x(I).lHeight = 42
            x(I).sTag = "Number " & I
            'x(I).Cell.nAlignment = 0
        Next
        L = Timer
        ReDim x(0) As udtItem
        Debug.Print "Using ReDim: " & (Timer - L)
        
        For I = 0 To 100000
            ReDim Preserve y(I) As udtItem
            y(I).bVisible = True
            y(I).lHeight = 42
            y(I).sTag = "Number " & I
            'y(I).Cell.nAlignment = 0
        Next
        L = Timer
        Erase y
        Debug.Print "Using Erase: " & (Timer - L)
        
        For I = 0 To 100000
            ReDim Preserve z(I) As udtItem
            z(I).bVisible = True
            z(I).lHeight = 42
            z(I).sTag = "Number " & I
            'z(I).Cell.nAlignment = 0
        Next
        L = Timer
        'How can I implement ZeroMemory to clear z() array???
    
        ZeroMemory z(0), Ubound(z) + 1 = VB CRASHES!
    
        Debug.Print "Using ZeroMemory: " & (Timer - L)
        
    End Sub
    Last edited by hennyere; Jul 16th, 2019 at 09:41 PM. Reason: comment

Tags for this Thread

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