file operation in binary vs text mode — performance concern

前端 未结 7 615
执笔经年
执笔经年 2020-12-31 10:04

In many projects, I saw that data object/structure are written into file in binary mode, and then retrieve them back from the file in binary mode again.

I wonder why

7条回答
  •  离开以前
    2020-12-31 10:21

    Only a few operating systems are affected by the choice between binary and text mode. None of the Unix or Linux systems do anything special for text mode—that is, text is the same as binary.

    Windows and VMS in particular transform data in text mode. Windows transforms \n into \r\n when writing to a file and the converse when reading. VMS has a file record structure to observe, so in the default mode, it translates \n into a record delimiter.

    Where it is different, binary is faster. If it is not different, it makes no difference.

提交回复
热议问题