Binary and Text Files

Sabbz

Well-Known Member
Joined
Jan 31, 2008
Messages
261
Reaction score
0
Location
Johannesburg
I have code that originally uses binary (file of byte), but I'm much more comfortable using text (Textfile). Using binary files is apparently faster, but I want to know by how much? Can one see a substantial speed difference?
 
Huh?

I'm assuming you're using C/C++.

There is no real difference between the two. The difference is in the methods used for reading from and writing to such files. Text files assume you are reading and writing chars. If you specifically need to read or write a byte at a time, or if your data stream contains null or special characters, you should use binary reading / writing.
 
If you specifically need to read or write a byte at a time, or if your data stream contains null or special characters, you should use binary reading / writing.

What he said :) Writing data out as text, you are going to limit yourself (most likely) to the ASCII character set (8 bits per character). You could use 16 or 32bit Unicode but you'll still have the same problems as mentioned before.

Another problem is what if your data stream isn't divisible by 8? They how do you represent this as text. If you insist on writing your data as text look at Base 64 encoding this is how email sends binary files as text.
 
Top
Sign up to the MyBroadband newsletter
X