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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redim speed question

Status
Not open for further replies.

richrock316

Programmer
Jul 30, 2003
57
US
I am creating a dynamic array with this statement
ReDim zoomarray(1).varray(amount)
where amount might start at 160K.
I later come in and increment with
ReDim zoomarray(2).varray(amount)
and so on until i get to the 10th element of the array. "amount" will get steadily smaller as we progress in the array.

My problem is that it takes about 2/10th of a second to create the first element of the array "zoomarray(1)", but it can take 5 seconds to do any of the successive elements even though the amount of records gets smaller.


Here are the global variables

Public zoomarray(1 To 10) As zarray

Type zoom_info
buffer As String * 10
Range As String * 8
bearing As String * 8
peak As String * 9
bkgrd As String * 8
ecm As String * 8
brng_extnt As String * 8
rng_extnt As String * 7
log As String * 4
mti As String * 4
test_trgt As String * 5
trgt_gate As String * 5
rpc_gate As String * 5
rng_extd As String * 5
azm_extd As String * 5
fail_bit As String * 4
group_id As String * 7
blip_count As String * 6
fcolor As Integer
newRange As String * 8
newbearing As String * 8
End Type

Type zarray
varray() As zoom_info
End Type
 
I ran a small test using your code and I found that changing your strings to varying length from fixed length produced about a 100-fold speed improvement. Fixed length strings involve a lot of processing overhead and they are mostly what is slowing your application down.
 
Golom,

Unfortunately I can't use variable-length strings (at least I think I can't) because I am reading in the data from a text file and I am using this procedure to read it in.

Line Input #intfile, strBuffer
i = i + 1
CopyMemory ByVal VarPtr(filearray(fileN).varray(i)), ByVal StrPtr(strBuffer), LenB(strBuffer)

I had to read it in this way insted of using something like split() because the input file may have extra padded spaces between lines, like so:

180.20 360.00 10279.2
192.60 5.25 1096.5

The columns start at the same place, so that is why I used a fixed-length string.

Any other suggestions?
 
Why not extract the smaller strings from the line using Mid function, e.g.

Field1 = mid(StrBuffer,1,4)
Field2 = mid(StrBuffer,5,8)
Field3 = mid(StrBuffer,9,6)

etc

then Field1, Field2 etc can be variable length
 
You might look at the Trim() function as well....

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Glasgow,

I tried breaking the strbuffer into smaller strings using mid() and it took twice as long.

Johnwm,

I'm not sure how the trim() function would help in this instance. What did you have in mind?

Richard
 
Clutching at straws perhaps and I've no idea of speed implications but could you consider doing substitutions to eliminate superfluous spaces.

e.g.
do while instr(strBuffer,&quot; &quot;)<>0
StrBuffer=Replace(StrBuffer, &quot; &quot;,&quot; &quot;)
Loop

then do split as you originally would have liked.
 
Sorry, that's difficult to read but basically, if there are still occurrences of two spaces in StrBuffer, replace them with a single space.
 
I have looked at the replace() method on this problem before and it was also slower.
 
Obviously your file has a crlf at the end of each line. Why don't you try reading the data in chunks to speed up the process if you are looking for speed.

' Open the files to work with
Open InputFile For Binary As #1
Open OutputFile For Output Access Write As #2 Len = 32767

NumOfRecBuffered = 64000 \ RecordSize
InputData = String(NumOfRecBuffered * RecordSize, 32)
LenOfFile = LOF(1)
NumOfRecords = LenOfFile \ (NumOfRecBuffered * RecordSize)
NumOfRecBuffered = NumOfRecBuffered - 1

For i = 1 To NumOfRecords
Get #1, , InputData
For j = 0 To NumOfRecBuffered
Print #2, Mid$(InputData, (RecordSize * j) + Position, Length)
Next j
Next i

' Empty buffer
PresentLoc = Loc(1)
InputData = String$(LenOfFile - PresentLoc, 32)
NumOfRecords = ((LenOfFile - PresentLoc) \ RecordSize) - 1
Get #1, , InputData
For j = 0 To NumOfRecords
Print #2, Mid$(InputData, (RecordSize * j) + Position, Length)
Next j

Close

Swi
 
Why Redim at all ?
Why not &quot;dim&quot; the array size initially to a maximum, and test that you don't exceed the theoretical maximum size.
If in fact you by chance do hit the maximum, only THEN use the redim statement.


 
I just got swamped by something else, but to let you know that your advice didn't go to waste I will be trying those suggestions within the next couple of days. I'll get back with you to know how it worked out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top