By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,566 Members | 1,762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,566 IT Pros & Developers. It's quick & easy.

Fastest, most frugal reading routine

P: n/a

I'm reading data from a text file, and having read a bit on performance and
memory, I'm wondering how it could be done in the fastest, most frugal way.

The data comes in messages, one per line, in a text file. I'm interested in
one of six messages, but I don't think there's any guarantee in the ordering
of the messages. Each message is identified by the first six characters in
the line.

Currently, I'm using a StreamReader, reading each line as a string using
ReadLine. Using StartsWith, I check to see if the line contains the data I
want. If it does, I parse the line, if not, I read the next line.

The downside to this approach is that I create a lot of meaningless strings
that do nothing but be collected by the garbage collector. Is there any way
to avoid that? I know it probably doesn't affect performance much, its more
a matter of principle - I'd like to know the best possible solution,
spending as little memory as possible. A problem is that the messages are of
varying length, so I can't read a regular amount of bytes in...

Let me know about your brilliant schemes to do this as efficiently as

Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.