Bifalgorithm post · Computer science one · Buffered and Unbuffered

When should data be stored as binary or text files?

When should data be stored as binary or text files? (Computer science one · Buffered and Unbuffered) — "9.1.4. Binary vs Text Files As previously mentioned, fi…

Ideas in this flowchart

  • Comparación entre archivos binarios y archivos de texto
  • Los archivos pueden almacenar datos binarios puros o texto plano ASCII
  • Si los datos deben ser legibles para las personas, se debe utilizar texto plano
  • En general, se recomienda almacenar los datos en formato binario
  • El formato binario suele requerir menos espacio de almacenamiento
  • El formato binario suele procesarse de manera más eficiente
  • Ejemplo: almacenamiento de una colección de enteros
  • En binario, cada entero requiere 4 bytes
  • Como texto, un entero requiere tantos bytes como dígitos tenga
  • El valor máximo representable requiere 10 caracteres ASCII, es decir, 10 bytes
  • La representación textual puede utilizar dos veces y media más memoria que la binaria
  • Los números escritos como texto necesitan delimitadores adicionales
  • En binario no se necesitan delimitadores porque cada bloque de 4 bytes representa un número
  • La diferencia de eficiencia puede ser aún mayor con números de punto flotante
Feed/

When should data be stored as binary or text files?

No cover

Channel

Computer science one

1 page

"9.1.4. Binary vs Text Files As previously mentioned, files can be stored as pure binary data or as plaintext (ASCII). Depending on our application and the nature of the data being written to files, the choice of which to use may be clear. If we want the data in our files to be human-readable, then we need to store them as plaintext. However, in general, we should prefer storing data in a binary format. The reason for this is that binary generally requires less space and is more efficient to process. Consider as an example, storing a collection of integers in a file. Each integer requires 4 bytes when represented in binary. However, when represented as a string, it requires as many bytes as there are digits in the number. For example, the maximum representable value of such an integer would be 2 31 − 1 = 2 , 147 , 483 , 647, requiring 10 ASCII characters and thus 10 bytes to represent, two and a half times as much memory as with the binary representation. Further, if a lot of numbers are stored, each number (as a string) would need to be delimited by yet another character. With a binary representation, no delimiter would be necessary as we would know that each 4 byte block represents a single number. This disparity can be even more stark with other types such as floating-point numbers."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.