Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mmap performance on iOS with frequent writes

I am using the mmap function on iOS in a drawing app. I have a file that uses mmap and then I create a CGBitmapContext from that memory. The user may perform many core graphics operations on this CGBitmapContext with their finger, which will cause the memory to be updated constantly.

How often will this flush to the flash storage and is this a concern for wearing out the flash storage or for performance? I haven't noticed anything bad in my tests, but I am not familiar enough with mmap to know for sure.

like image 536
jjxtra Avatar asked Nov 11 '22 19:11

jjxtra


1 Answers

iOS is pretty smart about how often it flushes to disk. I have noticed that when I background the app, as long as I call msync, i.e. msync(self.memoryMap, self.memoryMapLength, MS_SYNC); it flushes properly.

While I use the app, even if there is a crash or sudden termination, usually all data is saved. If I kill my app while debugging, sometimes the last few changes are not saved, but usually everything is saved.

So my conclusion is that this is not a concern. iOS is not constantly writing to disk, it is writing to disk at smart intervals.

like image 97
jjxtra Avatar answered Nov 15 '22 06:11

jjxtra