Difference between writing to file atomically and not

后端 未结 3 1396
孤城傲影
孤城傲影 2020-12-25 10:40

What is the difference in writing to files atomically on the iPhone in objective-c and not, is there any performance difference between the two?

3条回答
  •  不知归路
    2020-12-25 11:08

    Atomic in general means the operation cannot be interrupted will complete or have no effect. When writing files, that is accomplished by writing to a temporary file then replacing the original with the temporary when the write completes.

    A crash while writing an atomic file means the original is not modified and there is a garbage file that can be deleted. A crash while writing normally would mean an expected good file is corrupt.

    Performance wise the cost is minimal. During the write you will have two copies of a file. The file replace is a very simple operation at the file system level.

    Edit: thanks zneak

提交回复
热议问题