且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

提高手指画性能

更新时间:2023-11-19 15:50:28

CGPoints的NSArray?你的意思是NSValues持有CGPoints的NSArray?这是一种非常耗费时间的方法,可以保存您不断访问的大量值。您可以以更好的方式存储此信息。代表整个屏幕的二维C阵列是最明显的。您可能还想查看位图图像表示,并直接绘制到CGImage而不是维护一堆CGPoints。看看在石英2D编程指南

An NSArray of CGPoints? You mean an NSArray of NSValues holding CGPoints? That's an incredibly time-expensive way to hold what has to be a huge number of values that you access constantly. You could store this information in many better ways. A 2-dimensional C-array representing the entire screen is the most obvious. You may also want to look into bitmap image representations, and draw directly into a CGImage rather than maintaining a bunch of CGPoints. Take a look at the Quartz 2D Programming Guide.

编辑:

您的对象(下方)相当于 NSValue ,只是更专业一点。当你有很多很多物体时,这里有很多开销(当我的屏幕几乎已满时,我估计约为100,000;如果你没有删除重复数据,则需要更多;运行仪器来对其进行分析)。旧式C数据结构可能要快得多,因为您可以避免所有保留/释放,分配等。但是还有其他选择。对于 NSMutableSet ,如果您对CGPoints进行像素对齐,并在您的CGPoints上重载 -isEqual ,则重复点检查会快得多点对象。

Your object (below) is the equivalent of an NSValue, just a little more specialized. There's a lot of overhead going on here when you have many, many objects (~100,000 I'm guessing when the screen is nearly full; more if you're not removing duplicates; run Instruments to profile it). Old-style C data structures are likely to be much faster for this, because you can avoid all the retains/releases, allocations, etc. There are other options, though. Duplicate point checking would be much faster with an NSMutableSet if you pixel-align your CGPoints, and overload -isEqual on your Point object.

确保您对像素进行像素对齐。在分数像素上绘制(并将它们全部存储起来),可以大大增加所涉及的对象数量以及您正在进行的绘制量。即使你想要抗锯齿,至少将像素舍入为.5(或.25或某些)。 CGPoint由两个双打组成。你不需要那种精确度来绘制到屏幕上。

Do make sure you're pixel-aligning your data. Drawing on fractional pixels (and storing them all), could dramatically increase the number of objects involved and the amount of drawing you're doing. Even if you want the anti-aliasing, at least round the pixels to .5 (or .25 or something). A CGPoint is made up of two doubles. You don't need that kind of precision to draw to the screen.