Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use binary files?

Why all use binary files, if all can use XML ?

like image 653
Glebka Avatar asked Mar 22 '26 04:03

Glebka


2 Answers

Because of performance, of course, then XML is good when you have to define a tree structure but not all kind of data fits well with it. Would you store a 3d model inside a XML file? Or an image?

XML is good to handle text data, what about effective binary data like images, sounds, compressed files, whatever..

It's really verbose and heavy to be parsed and you don't want to use it when performance matters (think about the netcode of a game for example).

I would shoot myself if I have to read an XML file containing for example structures for vectors or points.

Using a parser instead that dumping content into memory with something like:

fread(&myBuf, sizeof(vector_struct), 10, in);

would make me feel stupid..

like image 62
Jack Avatar answered Mar 24 '26 22:03

Jack


Have you seen XML? It appears to be an insidious scheme by hardware manufacturers to sell larger hard disks :-)

However, humour aside, I would choose to use binary files if:

  • I wasn't too concerned about making the information available to outside systems, or portable to other platforms.
  • I wanted to read and write it in at maximum speed (without having to parse/produce XML).
  • I didn't need it human-readable, or easily transformed.
  • I was working on a system where XML didn't make sense (embedded C) or where XML processing libraries weren't readily available.
like image 23
paxdiablo Avatar answered Mar 24 '26 23:03

paxdiablo