Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substitute for NSData deprecated dataWithContentsOfMappedFile

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);
like image 302
mprivat Avatar asked Sep 27 '12 14:09

mprivat


Video Answer


1 Answers

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.

like image 69
Rob Napier Avatar answered Oct 17 '22 23:10

Rob Napier