简体   繁体   English

iPhone-改善磁盘瓶颈

[英]iPhone - improving disk bottleneck

I am designing this app and there's a section where the users are allowed to draw with their fingers. 我正在设计这个应用程序,并且有一个部分允许用户用手指绘制。 As I provide a undo for the operation, when the user starts drawing I have to quickly grab the current drawing content and store it somewhere. 当我为操作提供撤消操作时,当用户开始绘制图形时,我必须快速抓取当前图形内容并将其存储在某处。

I first tried to store the undo as a CGLayer and also as an image, but my app memory usage went up from 7 to 19 Mb. 我首先尝试将撤消存储为CGLayer和图像,但是我的应用程序内存使用从7 Mb上升到19 Mb。 With 19 MB I am relatively safe, because 24 Mb appears to be the theoretical limit beyond things start to be dangerous. 有了19 MB,我就比较安全了,因为24 Mb似乎是理论极限,已经超出了危险的范围。 The problem is that I have another section of my app that requires lots of memory and if I run this, the memory peaks from 19 to 28 Mb, that is too dangerous to risk. 问题是我的应用程序的另一部分需要大量内存,如果运行此部分,内存峰值将从19 Mb到28 Mb,这太危险了,无法冒险。

Then I decided to save the image on disk. 然后,我决定将映像保存在磁盘上。 To prevent the little gap that happens when the image has to be saved when the user fires TouchesBegan I refined, to the limits of sanity, the saving to disk method and now I barely don't feel any gap. 为了避免在用户触发TouchesBegin时必须保存图像时发生的微小缝隙,为了达到理智的程度,我改进了保存到磁盘的方法,现在我几乎感觉不到任何缝隙。 I said, I barely don't feel, but I still feel a little hair gap, I would say <0.1s that takes to the line start drawing. 我说,我几乎没有感觉,但是我仍然感觉到一些毛发间隙,我想说<0.1s就是开始画线的时间。

What I do is to fire a queue operation to manage the file saving. 我要做的是触发队列操作来管理文件保存。

Is there any other ways you guys can envision on how could this be improved? 你们还有其他方法可以设想如何改进它吗?

thanks 谢谢

I suggest to store the image as vector data, this way you could play and undo very quickly and divide by thousand times the memory used. 我建议将图像存储为矢量数据,这样您可以非常快速地进行播放和撤消操作,并将其除以所使用内存的千倍。 For example you can only store: 例如,您只能存储:

  • Gesture coordinates (x, y) 手势坐标(x,y)
  • Gesture type (touchBegan, touchEnded) 手势类型(touchBegan,touchEnded)
  • Pen changes (color, width, effect) 笔变化(颜色,宽度,效果)

You also have a canvas to render the current image. 您还可以使用画布来渲染当前图像。

Good luck! 祝好运!

Use mmap and CGBitmapContextCreate to create images that are backed by a file; 使用mmapCGBitmapContextCreate创建由文件支持的图像; the kernel will lazily page in and out parts of the file as they are needed. 内核将根据需要懒惰地调入和调出文件的各个部分。

Combine this with rjobidon's suggestion by snapshotting every so often and you should have a robust and speedy undo system. 经常通过快照将其与rjobidon的建议结合起来,您应该拥有一个强大而快速的撤消系统。

How about doing the storing at the end of the previous operation? 在上一个操作结束时如何存储? Then the beginning of each stroke will be instant. 然后,每个笔画的开始都是即时的。

You could even do it on a timer so it only saves an undo if you pause drawing for a few seconds, which would mean the undo takes them back to the previous stage of the drawing, rather than just the previous stroke, which may be desirable. 您甚至可以在计时器上执行此操作,这样,如果您暂停绘图几秒钟,它只会保存撤消操作,这意味着撤消操作会将其带回到绘图的前一阶段,而不仅仅是上一步,这可能是理想的。

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

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