Advantages of Binary Files over Text files in Search and read

U

utab

Dear all,

What are the advantages of binary files over text files? I would like
to search for a specific value of a variable in an output file, I was
doing this lately by the string library functions of the language. But
wondering the advantages of searching and reading from a binary file.
If the files get too large, I guess the advantage of reading from a
binary file is that it is much faster.

Regards,
 
D

Daniel T.

utab said:
What are the advantages of binary files over text files? I would like
to search for a specific value of a variable in an output file, I was
doing this lately by the string library functions of the language. But
wondering the advantages of searching and reading from a binary file.
If the files get too large, I guess the advantage of reading from a
binary file is that it is much faster.

An FAQ

http://www.parashift.com/c++-faq-lite/serialization.html#faq-36.3
 
M

mlimber

utab said:
What are the advantages of binary files over text files?

The latter are human-readable and are used for text-based applications
(e.g. a config file), while the former can be smaller and are used when
the data is not textual in nature (e.g., an image).
I would like
to search for a specific value of a variable in an output file, I was
doing this lately by the string library functions of the language. But
wondering the advantages of searching and reading from a binary file.
If the files get too large, I guess the advantage of reading from a
binary file is that it is much faster.

If it's all text that you're processing, then there may be no advantage
to using a binary file. You'll have to give us more details about what
it is you are saving to a file and searching for in order for us to
give you a better answer.

Cheers! --M
 
I

ionut.neicu

The implementations on different platforms can introduce various
differences.
Remember, if you open file in the text mode, you cant read over the EOF
char.
This is a problem if the file is a binary file ( an image for example
).

Text files, are usually sequential ( you cant't seek random in file ).
The sequential mode is sightly faster as random access.
Also text files can be optimized for sequential access. This option
can improve significant file acces speed.

Read CreateFile documentation from Windows API.
If you use Windows, use CreateFile with SEQUENTIAL_SCAN flag instead of
fopen, or so. The improvement in read speed is spectacular !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top