473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Speeding up array/file loading

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

Nov 16 '06 #1
3 1015

"Jarry" <Ha***********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.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
I had a similar problem when implementing a comprehensive "log file" class
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.


Nov 16 '06 #2
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.
------------------------------------

"Jarry" <Ha***********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.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

Nov 16 '06 #3

RobinS wrote:
>
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length
Thanks, I'm sure to try it out

Nov 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Spamtrap | last post by:
I only do occasional Perl programming and most things I write are short processes. I have something I'm working on that is scanning a text file with about 15 million lines and trying to extract...
2
by: Techie Guy | last post by:
I'm trying to process a tab delimited file where each line in the file has around 12 tab delimited elements. My problem is the elements are surrounded by "quotes" and I need the script to remove...
10
by: Sarah Smith | last post by:
Hello, I am a bit of a newbie to VB.NET, but not totally new. I took the plunge recently and decided (along with my colleagues), to try to convert/port a VB6 client/server app to .Net. (I'm...
4
by: Jm | last post by:
Hi all I know this might sound a little stupid but i thought id better ask anyway in case there are some things i havent already tried that everybody else knows. Basically i am wondering if...
1
by: bobmct | last post by:
Fellow PHP'ers; I'm digging myself a hole on this one so I thought it has come to the time when I must ask those who know. I have what should be a simple question for loading, accessing and...
4
by: Miro | last post by:
Im trying to store data as I would in some old language. Old Example //Create an array that holds 3 different variable types TempArray := { { "Hello", 1, False }, { "Goodbye", 123, True } } ...
3
by: Mark Reed | last post by:
All, I have built a database recently which resides on a network server which is constantly being re-structured. This is something I have no control over so have had to incorporate a means by...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
1
anfetienne
by: anfetienne | last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.