CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Arrays

  1. #1

    Arrays

    How do i delete items from a dynamic array? Is there an efficient way of manipulating dynamic arrays. I can use collection but that will slow my app. Any ideas? anyone?


  2. #2
    Join Date
    Jul 1999
    Posts
    145

    Re: Arrays

    Try writing yourself a vector class to wrap the array. Put error handling in an Add method to catch when you've exceeded array bounderies then redimension the array using the preserve keyword.
    You can also monitor to see when it is necessary to shrink the array. Vectors are much faster than collections but you can't really delete entries in the middle of the vector.

    To give you an idea here's some code out of "Hardcore Visual Basic" by Bruce McKinney:



    property let Item(byval i as long, byval ItemA as Variant)
    on error Goto FailLetItem
    av(i)=ItemA
    If i> iLast then iLast=1
    Exit property

    FailLetItem:
    If i>UBound(av) then
    Redim Preserve av(1 to i+cChunk) as Variant
    resume
    End if
    Err.Raise Err.Number
    End property



    Where cChunk is a set amount by wich the array will expand each time its upper boundery is exceeded.



  3. #3

    Re: Arrays

    thanks for the info. i've decided to go with collections instead of dealing with efficiency pain myself.


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

Featured