Re: Binary v. Text, why is it faster?
- From: Dave <solomons_dad.w.marks_and_whom@xxxxxxxxxx>
- Date: Tue, 07 Feb 2006 10:07:58 +0000
Arctic Fidelity wrote:
I have constantly seen and heard that reading binary data is faster than reading textual data. I have always presumed this to be a fact. But now I am at the point where I would like to understand why.
I was trying to think about it, and it has rather confused me. To my understanding, reading a text file is reading in the bytes which correspond to, for example, ASCII character codes. But if we are dealing with a 1-byte character encoding, how is it slower to read in 'a' rather than some binary representation of that?
And in addition to this, what is the actual difference between binary and textual files? I had always thought that a binary file was simply a file composed of any combination of bytes, whereas a text file was a file composed of a limited subset of the bytes available to a binary file. Am I misunderstanding something here?
I guess I just don't see how reading in AF would be slower just because AF appears in a text file instead of a "binary" file?
- Arctic
A point others haven't made yet is also that text files are often human-readable, so there can be additional stuff in there that has to be processed (and usually ignored), so for instance a binary representation of the numbers 1-5 might just contain five bytes 01 02 03 04 05, but a text version of the same data might read something like:
[object1]
numvalues=5
value1=1
value2=2
value3=3
value4=4
value5=5
The other difference between binary and text files is that end of line characters are significant in the latter. In a binary file an 0x0a is just an 0x0a, but on some operating systems this must be accompanied by an 0x0d. This is why it's important to ftp files in the correct mode, particularly if downloading, for instance, a text file created on Unix to a Windows box. If you download a binary file in text mode any 0x0a found will have an 0x0d added to it, thus corrupting the file.
Also some editors will helpfully display an unaccompanied 0x0a as ^M which is really helpful, thanks guys, really makes things a lot more readable, as if you didn't understand what had happened here.
Dave.
.
- References:
- Binary v. Text, why is it faster?
- From: Arctic Fidelity
- Binary v. Text, why is it faster?
- Prev by Date: Re: Binary v. Text, why is it faster?
- Next by Date: Re: Executable doesn't know location of data files
- Previous by thread: Re: Binary v. Text, why is it faster?
- Next by thread: Re: Binary v. Text, why is it faster?
- Index(es):
Relevant Pages
|