c++ - File Binary vs Text -


there situation have prefer binary file text file? i'm using c++ programming language?

example if have store large text file better use text file or binary file?

edit

file moment has no requirment readable human. performance difference, security difference , on?

edit

sorry omit other requirment (thanks carey gregory)

  • the record save in ascii encoding
  • the file must crypted ( aes )
  • the machine can power off time. i've try prevents errors.
  • i've know if file change outside program, think i'll use sha1 digest of file.

as general rule, define text format, , use it. it's easier develop , debug, , it's easier see going wrong if doesn't work.

if find files becoming big, or taking time transfer on wire, consider compressing them. compressed text file smaller can binary. or consider less verbose text format; it's possible reliably transmit text representation of data lot less characters xml uses.

and finally, if end having use binary, try chose existing format (e.g. google's protocol blocks), or base format on existing format. remember that:

  • binary lot more work text, since practically have write of << operators again, including in standard library.

  • binary lot more difficult debug, because can't see you've done.

concerning last edit:

  • once you've encrypted, results binary. can use text representation of binary (base64 or such), results won't more readable binary, it's not worth bother. if you're encrypting in process, before writing disk, automatically lose of advantages of text.

  • the issues concerning powering off mean cannot use ofstream directly. must open or create file necessary options full transactional integrity (o_sync flag open under unix). must write each record single write request system.

  • it's idea have checksum, in case. if you're worried security, sha1 choice. keep in mind if has access file, , wants intentionally change it, can recalculate sha1 , insert new value well.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -