简体   繁体   English

writeToFile:atomically:原子意味着什么?

[英]writeToFile:atomically: what does atomically mean?

I am wondering what the atomically: parameter stands for in the writeToFile:atomically: method ( -[NSArray writeToFile:atomically:] for example). 我想知道writeToFile:atomically: atomically:参数在writeToFile:atomically: method( -[NSArray writeToFile:atomically:]中)代表什么。 It is common to pass YES for atomically: , but I don't know what it means. atomically:方式传递YES是很常见的,但我不知道它意味着什么。

An 'atomic write' is one where you are guaranteed to have either a correct, complete write to the file or an error. “原子写入”是指保证对文件进行正确,完整写入或错误的原子写入。 There's no chance that, say, half of the write will work and then something bad happens (lost power, drive crash, etc) and the rest of the write fails. 例如,写入的一半将无法工作,然后发生一些不好的事情(断电,驱动器崩溃等),其余的写入失败。 It's all or nothing. 这是全有或全无。 This is generally what you want. 这通常是你想要的。

atomically 原子

If YES, the data is written to a backup file, and then—assuming no errors occur—the backup file is renamed to the name specified by path; 如果是,则将数据写入备份文件,然后 - 假设没有发生错误 - 将备份文件重命名为path指定的名称; otherwise, the data is written directly to path. 否则,数据直接写入路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM