Difference between writing to file atomically and not

后端 未结 3 1377
孤城傲影
孤城傲影 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:00

    Filesystems don't have to resort to write/rename cycles for atomic writes. Filesystems that have locking semantics allow you to 'lock' portions or all of a file, or in some cases even do things like appends to a file, to help with atomicity.

    @Randy, both your assumptions about fragmentation are likely to be wrong. On most filesystems, writing an entire file and closing it will result in a less fragmented file, and writing a large file in a single write will definitely result in better usage of large blocks. If you meant the file blocks were more likely to 'creep' across the disk, that depends on the layout preferences in your filesystem. If you're writing to flash, you probably want the filesystem to creep across the available storage as a sort of self-levelling of the writes.

提交回复
热议问题