Substitute for NSData deprecated dataWithContentsOfMappedFile

怎甘沉沦 提交于 2019-12-19 07:52:15

问题


So +(id)dataWithContentsOfMappedFile:(NSString *)path is apparently deprecated since iOS 5.0. It sounds to me like I should avoid using it, but then what should I use instead?

I was using mmap to create memory mapped files and it worked with iOS5, but in iOS6, something is wrong because I get an error as soon as I try to update or read the buffer.

  int fd = open(path, O_RDWR);
  off_t offset = 0;
  snapshotData = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
  close(fd);

回答1:


Use +dataWithContentsOfFile:options:error:. Pass NSDataReadingMappedIfSafe as the option. You can also use NSDataReadingMappedAlways instead, but I recommend the former unless it really has to be mapped. If it really must be mapped, NSDataReadingMappedAlways is still just a hint, so there's no promise. To get a promise, you need to write it yourself, as discussed at CIMG.



来源:https://stackoverflow.com/questions/12623622/substitute-for-nsdata-deprecated-datawithcontentsofmappedfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!