469,950 Members | 1,828 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Fastest, most frugal reading routine

Hi,

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
possible!

Regards,
Einar
Nov 15 '05 #1
0 1240

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Einar HÝst | last post: by
1 post views Thread by Jim Hubbard | last post: by
3 posts views Thread by _DD | last post: by
22 posts views Thread by SETT Programming Contest | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.