|
-
Feb 10th, 2005, 10:07 PM
#1
Thread Starter
Frenzied Member
Dynamic arrays in visual basic - do they exist?
Anyone know?
for example, how can i add items to a string array, without defining a size?
i hate having to redim preserve string (ubound(string) + 1) for each and every item i add to it... and it just seems that for thousands of items, this would be slow (btw i dont know know how many items to add - i just parse data and add them as they come along)
Also, how can u 'clear' an array?
-
Feb 10th, 2005, 10:12 PM
#2
Re: Dynamic arrays in visual basic - do they exist?
I don't know if it will slow you down at all, but you may want to use a collection or a class instead of an array.
To clear an array, use
-
Feb 10th, 2005, 10:14 PM
#3
Thread Starter
Frenzied Member
Re: Dynamic arrays in visual basic - do they exist?
 Originally Posted by dglienna
I don't know if it will slow you down at all, but you may want to use a collection or a class instead of an array.
To clear an array, use
i think collections are even slower than arrays.. and i dont know about clases
-
Feb 10th, 2005, 10:14 PM
#4
Junior Member
Re: Dynamic arrays in visual basic - do they exist?
If you are "sometimes" adding data to an array,
redim preserve string (ubound(string) + 1)
will be OK. But if you are adding lots of data all the time, test the ubound(string) with the current index of the array for which you want to add data to, and if it's close, add another 500.
redim preserve string (500)
|
+--Thief_
|
+--VB6
+--VB Dot Net
|
-
Feb 10th, 2005, 10:34 PM
#5
Re: Dynamic arrays in visual basic - do they exist?
 Originally Posted by VaxoP
Anyone know?
for example, how can i add items to a string array, without defining a size? ...
You can't.
-
Feb 11th, 2005, 12:27 AM
#6
Re: Dynamic arrays in visual basic - do they exist?
If you are "sometimes" adding data to an array,
redim preserve string (ubound(string) + 1)
will be OK. But if you are adding lots of data all the time, test the ubound(string) with the current index of the array for which you want to add data to, and if it's close, add another 500.
It's been my experience that ReDimming in large chunks is actually slower than ReDimming by 1 as required. It may have something to do with the way VB grabs memory and this would get worse as available memory dropped or if available memory was fragmented.
If you're interested, check this post for some discussion on the pros & cons of using Redim Preserve and arrays versus collections.
http://www.vbforums.com/showthread.php?t=246059
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Feb 13th, 2005, 04:59 PM
#7
Junior Member
Re: Dynamic arrays in visual basic - do they exist?
Good reference Pete! Thanks.
|
+--Thief_
|
+--VB6
+--VB Dot Net
|
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|