Re: Binary file read/write

Tech-Archive recommends: Fix windows errors by optimizing your registry



Dave O. wrote:
"Sinna" <news4sinna_NOSPAM@xxxxxxxxxx> wrote in message news:ehx0weM4IHA.4332@xxxxxxxxxxxxxxxxxxxxxxx
Dave O. wrote:
Spoilsport, you made it far too easy for him :-)
I see your answer is the same as my suspicion, good to know I was correct.
At this point it might be worth pointing out to the OP that reading in (or writing out) a file byte by byte is kinda inefficient and slow, in most cases it's far better to read the whole file into a string or byte array in a single pass, then get whatever bytes are required.

Regards
Dave O.

Apart from a FileCopy (mentioned elsewhere), I wouldn't assume the file is 'small' enough to get it completely read in memory. When dealing with 2GB+ (and I assume quite a lot smaller too) you'll get Out of Memory errors.

About improving speed, when copying from a disc to another, look up the memory buffer of the disc and use that as pass-thru buffer.


Sinna

As I read it the OP was not trying to do a plain copy but was trying to understand how to read & write a file so FileCopy is not applicable.
Certainly reading a 2G file into memory in a single pass would cause problems but reading it in byte by byte would take for ever, so for huge files the best method would be to read in chucks of a few Meg at a time.

Regards
Dave O.


You get me correctly.
Copying using chuncks of a few Meg is very efficient when using chuncks <= memory buffer of the hard disc.

Sinna
.


Quantcast