|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Speeding up array/file loadingI have two arrays to load, taking one line to an entry from two 770,000
line files: so I have two arrays of 770000. But this can take upwards of 5 minutes, which is simply too long. I use a stream reader to readline from the textfiles, using the syntax For i = 1 to 770000 myArray(i) = myStreamReader.readLine() Next How can I speed this process up, but try to keep the arrays that size? All ideas welcomed. Thanks, Jarry
Show quote
Hide quote
"Jarry" <HarryandJa***@gmail.com> wrote in message I had a similar problem when implementing a comprehensive "log file" class news:1163697284.597263.22210@b28g2000cwb.googlegroups.com... >I have two arrays to load, taking one line to an entry from two 770,000 > line files: so I have two arrays of 770000. But this can take upwards > of 5 minutes, which is simply too long. I use a stream reader to > readline from the textfiles, using the syntax > For i = 1 to 770000 > myArray(i) = myStreamReader.readLine() > Next > > How can I speed this process up, but try to keep the arrays that size? > All ideas welcomed. > > Thanks, > Jarry > for my software. When in Verbose mode, the logs can easily expand to over 100mb pretty quickly. The solution I came up with was to write each line of the log file fixed width, i.e. say, 128 characters in width. Then I don't have to "readline" (which needs to scan for a newline character), I can just suck in 128 characters at a time, or any multiple of 128 characters. The resulting log file is larger than it would have been without fixed width, but I can easily display it using Virtual Mode in a list view pretty much in real-time. If I were you, I would at least read a large chunk of the file at a time and do your processing in memory rather than from disk. Get your stream reader to read in 10mb at a time into a byte array and then split the byte array by newline into your "myArray". You'll have tricky cases around the edges of each chunk but it will be an order of magnitude quicker to do it that way. Assuming each line has a carriage-return/line-feed at the end
(and it must, or readLine wouldn't work), here's an easy way to read in a file and split the lines by Crlf into an array in one fell swoop. Dim crlfs() as String = {ControlChars.CrLf} Dim lines() as String = _ File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None) Dim numOfLines = lines.Length Thanks to Francesco Balena; I got this out of one of his books, probably the VB2005 Core Reference. Robin S. ------------------------------------ Show quoteHide quote "Jarry" <HarryandJa***@gmail.com> wrote in message news:1163697284.597263.22210@b28g2000cwb.googlegroups.com... >I have two arrays to load, taking one line to an entry from two 770,000 > line files: so I have two arrays of 770000. But this can take upwards > of 5 minutes, which is simply too long. I use a stream reader to > readline from the textfiles, using the syntax > For i = 1 to 770000 > myArray(i) = myStreamReader.readLine() > Next > > How can I speed this process up, but try to keep the arrays that size? > All ideas welcomed. > > Thanks, > Jarry > RobinS wrote:
> Thanks, I'm sure to try it out> Dim crlfs() as String = {ControlChars.CrLf} > Dim lines() as String = _ > File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None) > Dim numOfLines = lines.Length >
RaiseEvent
Howto Identify an Exception? Export function from VB.Net DLL vb 2005 standard question Can a base class implement a method on an interface for me? how mutch memory aspnet_wp.exe must use Class.New and DB mapping SECURITY PROBLEMS IN VB.NET Using Visual Studio .NET 2005 to compile to ASP.NET 1.1 VS2005 SP1 beta |
|||||||||||||||||||||||