Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rediming an array in a loop

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Good afternoon. I was looking at using an array in some code to store the position of a variable number of a certain character within a cell and came across this:

But do note that both ReDim and particularly ReDim Preserve have a heavy performance cost. Try to avoid doing this over and over in a loop if at all possible; your users will thank you.

Now, my loop would probably only be about a dozen each time - if I decide to go down this road - but could be for thousands of rows of data. Would this actually have an impact (a discernible impact!) on what I ran? Or should I dim 0 to 100 instead?

Many thanks,
D€$
 
hi,

I run a test to see.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
ReDim Preserve is time consuming, but in milliseconds ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanx PHV. Skip, I see what you mean. Probably wouldn't be able to notice the difference then! [neutral]

Many thanks,
D€$
 
As far as I know (I may be wrong, not the first time :) ), when you use ReDim or ReDim Preserve, you are actually making a copy of the (previous) array with additional empty elements. So if you ReDim an array 5 times, you have in memory 6 ‘instances’ of that array (1 initial empty one and 5 new arrays bigger and bigger).

Have fun.

---- Andy
 
If that's what really happens, then it might be a factor with 'donut memory', but with gigs? Hmmmmmmmmmm? Probably not.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I have read something about ReDim or ReDim Preserve some time ago and that was the explanation of how it works. Like I said, I may be way off...

Have fun.

---- Andy
 
Well, you are sort of right that it makes a copy (well ReDim Preserve does), although it's a little more complex than that - but it discards the original.
 
OK, thanx all.

Many thanks,
D€$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top