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