Re: Reading Files Byte-For-Byte
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Sun, 18 Dec 2005 14:17:10 -0600
<PulsarSL@xxxxxxxxx> wrote in message
> Norm Cook wrote:
> > A bit confusing here. You want to read the file byte by byte but you are
> > attempting to read the file into an array.
>
> Yea, some code I found did it this way, but since Larry said it's slow,
> I guess I'll abandon the array --
You have misunderstood my message:
>> Is this how I should be doing it?
> Yes, you don't really want to read the file byte by byte due to low performance.
But you did not post the code for a byte by byte method, you posted code
for a single read operation.
The method you showed was the more performant method, so that was
how you should proceed. Reading byte for byte (on larger files) is going
to be slower due simply to the additional commands required to accomplish
the task. You much rather want to read the whole file in one go, storing it
in an array for easy access. Please read my message again and see if it now
better answers your question. I provided the code example for completeness,
to show how it would look with declared variables and the use of FreeFile.
However, when working with files, error handling is also advised but was not
shown.
I think the misunderstanding came about due to your mentioning reading the
file byte by byte, but showing code that reads the entire file in one shot. Reading
byte for byte requires some looping mechanism, which was also posted, but
is going to be slower, again due to the sheer number of commands needed
to accomplish the task. The difference is not going to be very noticable on
smaller files, but reading the entire file into a single array will make for easier
processing later on, when you need to write out the data. Also note how
my example code converted the first to bytes into printable characters for
the Debug command. While that will work for bytes that fall within the range
of printable characters, you'll need to do something else if your file data falls
outside that range (which image data is certain to do).
LFS
.
- Follow-Ups:
- Re: Reading Files Byte-For-Byte
- From: PulsarSL
- Re: Reading Files Byte-For-Byte
- References:
- Reading Files Byte-For-Byte
- From: PulsarSL
- Re: Reading Files Byte-For-Byte
- From: Norm Cook
- Re: Reading Files Byte-For-Byte
- From: PulsarSL
- Reading Files Byte-For-Byte
- Prev by Date: Re: Reading Files Byte-For-Byte
- Next by Date: Re: Selecting tab with mouse right click on TabStrip
- Previous by thread: Re: Reading Files Byte-For-Byte
- Next by thread: Re: Reading Files Byte-For-Byte
- Index(es):
Relevant Pages
|