iphone - 如何优化quartz 2d?

标签 iphone objective-c optimization

我有一段代码,本质上是:

    for(int i=0;i<aInt;i++){
        CGPoint points[2] = {CGPointMake(i,0),CGPointMake(i,bArray[i])};
        CGContextStrokeLineSegments(myContext, points, 2);
    }

当 aInt 变大时,这会造成一些瓶颈,就像我的情况一样。我对quartz 2d了解不够,不知道如何最好地优化它。是否最好在循环中创建一个巨大的点数组,然后对整个数组进行一次斯托克?

或者更理想的是,我刚刚优化了处理数组的代码的不同部分。在这样做的过程中,我转而使用 C 风格的数组,这极大地加快了速度。是否有类似的低级方法来执行上述操作?

谢谢!

最佳答案

我还认为制作一个大数组会使其速度更快。对 CGContextStrokeLineSegments 的调用肯定会减少。

CGPoint *points = (CGPoint*)malloc(sizeof(CGPoint)*aInt*2);

for(int i=0;i<aInt;i++){
    points[i*2] = CGPointMake(i,0);
    points[i*2+1] = CGPointMake(i,bArray[i]));
}

CGContextStrokeLineSegments(myContext, points, aInt*2);

free(points);

关于iphone - 如何优化quartz 2d?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1995391/

相关文章:

Mysql 不使用 group by 和 order by 索引

iPhone卡片像翻转动画

objective-c - Autolayout NSScrollview 不增长 contentView

IOS如何彻底删除一个View

objective-c - iOS 核心数据 - 段错误 11

iOS 9 Beta 5 - 日历隐私访问警报未显示在 iPhone 上,但显示在模拟器上

javascript - 跨域拆分请求——阻止过度的安全性

algorithm - 将两条线拟合到一组 2D 点

iphone - (iphone) 特定 IP/端口的可达性测试?

iphone - 在 Objective-C : How to show 3 values on 1 row?