arrays - VB.net Alternative way of ReDim Preserve -


my program work think suffers performance issues, consuming upto 40% of total cpu usage while looping array. programs consume under 5% of cpu usage, think redim preserve causing looping around 100,000+ of lines. here code.

    dim sarray string()     dim fstream new system.io.filestream("messages.txt", io.filemode.open)     dim sreader new system.io.streamreader(fstream)     dim index integer = 0     while sreader.peek >= 0         redim preserve sarray(index)         sarray(index) = sreader.readline         index += 1     loop      fstream.close()     sreader.close() 

is there alternative way of placing values array aside redim preserve? in advance, trapped problem right now.

here updated code using list.

    dim sarray string()     dim slist new list(of string)     dim fstream new system.io.filestream("messages.txt", io.filemode.open)     dim sreader new system.io.streamreader(fstream)     dim index integer = 0     while sreader.peek >= 0         slist.add(sreader.readline)     loop     sarray = slist.toarray      fstream.close()     sreader.close() 

i still needed funcionalities of array created array , placed contents of list it.

you should use list(of string), leave room future elements instead of resizing every time.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -