- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是一个真正的谜。
假设您正在执行在屏幕外绘制复杂图像 (CGLayer) 的传统过程,并且在绘制时间歇性地将图像更新到屏幕上。
如您所知,执行此操作的方法是:在后台运行大型绘图过程,并根据需要调用前台的 setNeedsDisplays,从而更新图像。这很简单,只需两行代码即可实现。
但是,当您这样做时,会出现一个神秘的问题:每次绘制周期所花费的时间,每次都在增加,变得无法使用。此外,时间可能会不规律地变化。
这是一个已知的 iOS 错误,还是?有人以前见过这个吗?
这是一个非常简单、非常容易理解的应用程序,它演示了这个问题:
http://www.fileswap.com/dl/p8lU3gAi/stepwiseDrawingV2.zip.html
输出示例如下。
有人知道为什么会这样吗?这是操作系统的非常奇怪的行为。
稍后 ... FELZ 想出了一个惊人的解决方法。 Felz 每轮复制 CGLayer 一次。这完全阻止了奇怪的行为。
然而,对于到底发生了什么,仍然没有真正清楚的理解:因此,从字面上看,当这个奇怪的问题出现时,时间用在了哪里?
这是一个很长的输出示例......
请注意,您有时会得到如下所示的“双重怪异”结果:它表现出“正常”的怪异行为:每转一圈时间都会增加。然而,偶尔时间会下降到“非常快”几轮,然后返回。很奇怪吧?此外,如果您在模拟器上运行,请快速前后点击 Mac 上不相关的应用程序以获得“更奇怪”的结果。
虽然 Felz 给出了完美的工作答案,但实际机制仍然是个谜。
:26:56.697 stepwiseDrawing[5334:1a03] time difference was 0
:26:56.707 stepwiseDrawing[5334:1a03] time difference was 10
:26:56.717 stepwiseDrawing[5334:1a03] time difference was 10
:26:56.744 stepwiseDrawing[5334:1a03] time difference was 27
:26:56.771 stepwiseDrawing[5334:1a03] time difference was 27
:26:56.807 stepwiseDrawing[5334:1a03] time difference was 37
:26:56.829 stepwiseDrawing[5334:1a03] time difference was 22
:26:56.864 stepwiseDrawing[5334:1a03] time difference was 35
:26:56.891 stepwiseDrawing[5334:1a03] time difference was 28
:26:56.936 stepwiseDrawing[5334:1a03] time difference was 45
:26:56.949 stepwiseDrawing[5334:1a03] time difference was 12
:26:56.981 stepwiseDrawing[5334:1a03] time difference was 32
:26:57.008 stepwiseDrawing[5334:1a03] time difference was 27
:26:57.041 stepwiseDrawing[5334:1a03] time difference was 33
:26:57.074 stepwiseDrawing[5334:1a03] time difference was 34
:26:57.109 stepwiseDrawing[5334:1a03] time difference was 34
:26:57.143 stepwiseDrawing[5334:1a03] time difference was 35
:26:57.179 stepwiseDrawing[5334:1a03] time difference was 36
:26:57.220 stepwiseDrawing[5334:1a03] time difference was 42
:26:57.271 stepwiseDrawing[5334:1a03] time difference was 51
:26:57.312 stepwiseDrawing[5334:1a03] time difference was 40
:26:57.356 stepwiseDrawing[5334:1a03] time difference was 45
:26:57.400 stepwiseDrawing[5334:1a03] time difference was 44
:26:57.447 stepwiseDrawing[5334:1a03] time difference was 46
:26:57.493 stepwiseDrawing[5334:1a03] time difference was 46
:26:57.542 stepwiseDrawing[5334:1a03] time difference was 49
:26:57.593 stepwiseDrawing[5334:1a03] time difference was 50
:26:57.707 stepwiseDrawing[5334:1a03] time difference was 114
:26:57.766 stepwiseDrawing[5334:1a03] time difference was 58
:26:57.801 stepwiseDrawing[5334:1a03] time difference was 36
:26:57.856 stepwiseDrawing[5334:1a03] time difference was 55
:26:57.918 stepwiseDrawing[5334:1a03] time difference was 62
:26:57.976 stepwiseDrawing[5334:1a03] time difference was 58
:26:58.039 stepwiseDrawing[5334:1a03] time difference was 62
:26:58.101 stepwiseDrawing[5334:1a03] time difference was 63
:26:58.165 stepwiseDrawing[5334:1a03] time difference was 63
:26:58.229 stepwiseDrawing[5334:1a03] time difference was 64
:26:58.294 stepwiseDrawing[5334:1a03] time difference was 66
:26:58.365 stepwiseDrawing[5334:1a03] time difference was 70
:26:58.436 stepwiseDrawing[5334:1a03] time difference was 72
:26:58.507 stepwiseDrawing[5334:1a03] time difference was 70
:26:58.572 stepwiseDrawing[5334:1a03] time difference was 65
:26:58.652 stepwiseDrawing[5334:1a03] time difference was 81
:26:58.726 stepwiseDrawing[5334:1a03] time difference was 74
:26:58.809 stepwiseDrawing[5334:1a03] time difference was 82
:26:58.879 stepwiseDrawing[5334:1a03] time difference was 70
:26:58.965 stepwiseDrawing[5334:1a03] time difference was 87
:26:59.043 stepwiseDrawing[5334:1a03] time difference was 77
:26:59.126 stepwiseDrawing[5334:1a03] time difference was 83
:26:59.210 stepwiseDrawing[5334:1a03] time difference was 84
:26:59.215 stepwiseDrawing[5334:1a03] time difference was 6
:26:59.310 stepwiseDrawing[5334:1a03] time difference was 95
:26:59.397 stepwiseDrawing[5334:1a03] time difference was 87
:26:59.486 stepwiseDrawing[5334:1a03] time difference was 89
:26:59.577 stepwiseDrawing[5334:1a03] time difference was 91
:26:59.668 stepwiseDrawing[5334:1a03] time difference was 91
:26:59.768 stepwiseDrawing[5334:1a03] time difference was 100
:26:59.856 stepwiseDrawing[5334:1a03] time difference was 88
:26:59.857 stepwiseDrawing[5334:1a03] time difference was 1
:26:59.965 stepwiseDrawing[5334:1a03] time difference was 108
:27:00.064 stepwiseDrawing[5334:1a03] time difference was 100
:27:00.165 stepwiseDrawing[5334:1a03] time difference was 101
:27:00.268 stepwiseDrawing[5334:1a03] time difference was 103
:27:00.371 stepwiseDrawing[5334:1a03] time difference was 103
:27:00.377 stepwiseDrawing[5334:1a03] time difference was 7
:27:00.493 stepwiseDrawing[5334:1a03] time difference was 115
:27:00.601 stepwiseDrawing[5334:1a03] time difference was 108
:27:00.710 stepwiseDrawing[5334:1a03] time difference was 109
:27:00.820 stepwiseDrawing[5334:1a03] time difference was 111
:27:00.939 stepwiseDrawing[5334:1a03] time difference was 119
:27:01.053 stepwiseDrawing[5334:1a03] time difference was 114
:27:01.162 stepwiseDrawing[5334:1a03] time difference was 108
:27:01.278 stepwiseDrawing[5334:1a03] time difference was 116
:27:01.396 stepwiseDrawing[5334:1a03] time difference was 118
:27:01.515 stepwiseDrawing[5334:1a03] time difference was 119
:27:01.637 stepwiseDrawing[5334:1a03] time difference was 122
:27:01.648 stepwiseDrawing[5334:1a03] time difference was 11
:27:01.769 stepwiseDrawing[5334:1a03] time difference was 121
:27:01.775 stepwiseDrawing[5334:1a03] time difference was 6
:27:01.910 stepwiseDrawing[5334:1a03] time difference was 135
:27:01.911 stepwiseDrawing[5334:1a03] time difference was 1
:27:02.045 stepwiseDrawing[5334:1a03] time difference was 134
:27:02.175 stepwiseDrawing[5334:1a03] time difference was 131
:27:02.314 stepwiseDrawing[5334:1a03] time difference was 139
:27:02.441 stepwiseDrawing[5334:1a03] time difference was 127
:27:02.586 stepwiseDrawing[5334:1a03] time difference was 145
:27:02.715 stepwiseDrawing[5334:1a03] time difference was 129
:27:02.853 stepwiseDrawing[5334:1a03] time difference was 138
:27:03.000 stepwiseDrawing[5334:1a03] time difference was 146
:27:03.133 stepwiseDrawing[5334:1a03] time difference was 134
:27:03.276 stepwiseDrawing[5334:1a03] time difference was 142
:27:03.419 stepwiseDrawing[5334:1a03] time difference was 143
:27:03.564 stepwiseDrawing[5334:1a03] time difference was 145
:27:03.717 stepwiseDrawing[5334:1a03] time difference was 153
:27:03.858 stepwiseDrawing[5334:1a03] time difference was 141
:27:04.008 stepwiseDrawing[5334:1a03] time difference was 149
:27:04.159 stepwiseDrawing[5334:1a03] time difference was 151
:27:04.318 stepwiseDrawing[5334:1a03] time difference was 159
:27:04.471 stepwiseDrawing[5334:1a03] time difference was 153
:27:04.620 stepwiseDrawing[5334:1a03] time difference was 149
:27:04.778 stepwiseDrawing[5334:1a03] time difference was 158
:27:04.939 stepwiseDrawing[5334:1a03] time difference was 161
:27:05.098 stepwiseDrawing[5334:1a03] time difference was 160
:27:05.269 stepwiseDrawing[5334:1a03] time difference was 171
:27:05.433 stepwiseDrawing[5334:1a03] time difference was 164
:27:05.600 stepwiseDrawing[5334:1a03] time difference was 166
:27:05.765 stepwiseDrawing[5334:1a03] time difference was 165
:27:05.932 stepwiseDrawing[5334:1a03] time difference was 167
:27:06.107 stepwiseDrawing[5334:1a03] time difference was 175
:27:06.269 stepwiseDrawing[5334:1a03] time difference was 163
:27:06.441 stepwiseDrawing[5334:1a03] time difference was 171
:27:06.617 stepwiseDrawing[5334:1a03] time difference was 176
:27:06.798 stepwiseDrawing[5334:1a03] time difference was 181
:27:06.971 stepwiseDrawing[5334:1a03] time difference was 173
:27:07.154 stepwiseDrawing[5334:1a03] time difference was 183
:27:07.326 stepwiseDrawing[5334:1a03] time difference was 172
:27:07.513 stepwiseDrawing[5334:1a03] time difference was 187
:27:07.689 stepwiseDrawing[5334:1a03] time difference was 176
:27:07.875 stepwiseDrawing[5334:1a03] time difference was 185
:27:08.059 stepwiseDrawing[5334:1a03] time difference was 184
:27:08.251 stepwiseDrawing[5334:1a03] time difference was 192
:27:08.432 stepwiseDrawing[5334:1a03] time difference was 181
:27:08.620 stepwiseDrawing[5334:1a03] time difference was 188
:27:08.811 stepwiseDrawing[5334:1a03] time difference was 190
:27:09.004 stepwiseDrawing[5334:1a03] time difference was 193
:27:09.195 stepwiseDrawing[5334:1a03] time difference was 191
:27:09.393 stepwiseDrawing[5334:1a03] time difference was 198
:27:09.590 stepwiseDrawing[5334:1a03] time difference was 197
:27:09.795 stepwiseDrawing[5334:1a03] time difference was 205
:27:09.989 stepwiseDrawing[5334:1a03] time difference was 193
:27:10.189 stepwiseDrawing[5334:1a03] time difference was 200
:27:10.392 stepwiseDrawing[5334:1a03] time difference was 203
:27:10.600 stepwiseDrawing[5334:1a03] time difference was 208
:27:10.801 stepwiseDrawing[5334:1a03] time difference was 202
:27:11.006 stepwiseDrawing[5334:1a03] time difference was 205
:27:11.220 stepwiseDrawing[5334:1a03] time difference was 213
:27:11.430 stepwiseDrawing[5334:1a03] time difference was 210
:27:11.633 stepwiseDrawing[5334:1a03] time difference was 203
:27:11.843 stepwiseDrawing[5334:1a03] time difference was 210
:27:12.055 stepwiseDrawing[5334:1a03] time difference was 213
:27:12.276 stepwiseDrawing[5334:1a03] time difference was 220
:27:12.484 stepwiseDrawing[5334:1a03] time difference was 208
:27:12.700 stepwiseDrawing[5334:1a03] time difference was 216
:27:12.919 stepwiseDrawing[5334:1a03] time difference was 219
:27:13.145 stepwiseDrawing[5334:1a03] time difference was 226
:27:13.360 stepwiseDrawing[5334:1a03] time difference was 215
:27:13.584 stepwiseDrawing[5334:1a03] time difference was 224
:27:13.813 stepwiseDrawing[5334:1a03] time difference was 229
:27:14.049 stepwiseDrawing[5334:1a03] time difference was 236
:27:14.269 stepwiseDrawing[5334:1a03] time difference was 220
:27:14.496 stepwiseDrawing[5334:1a03] time difference was 228
:27:14.725 stepwiseDrawing[5334:1a03] time difference was 229
:27:14.963 stepwiseDrawing[5334:1a03] time difference was 238
:27:15.196 stepwiseDrawing[5334:1a03] time difference was 232
:27:15.423 stepwiseDrawing[5334:1a03] time difference was 227
:27:15.657 stepwiseDrawing[5334:1a03] time difference was 235
:27:15.901 stepwiseDrawing[5334:1a03] time difference was 243
:27:16.133 stepwiseDrawing[5334:1a03] time difference was 232
:27:16.372 stepwiseDrawing[5334:1a03] time difference was 240
:27:16.613 stepwiseDrawing[5334:1a03] time difference was 241
:27:16.863 stepwiseDrawing[5334:1a03] time difference was 250
:27:17.101 stepwiseDrawing[5334:1a03] time difference was 238
:27:17.346 stepwiseDrawing[5334:1a03] time difference was 245
:27:17.593 stepwiseDrawing[5334:1a03] time difference was 247
:27:17.849 stepwiseDrawing[5334:1a03] time difference was 256
:27:18.093 stepwiseDrawing[5334:1a03] time difference was 244
:27:18.344 stepwiseDrawing[5334:1a03] time difference was 251
:27:18.603 stepwiseDrawing[5334:1a03] time difference was 260
:27:18.854 stepwiseDrawing[5334:1a03] time difference was 251
:27:19.114 stepwiseDrawing[5334:1a03] time difference was 259
:27:19.376 stepwiseDrawing[5334:1a03] time difference was 263
:27:19.646 stepwiseDrawing[5334:1a03] time difference was 270
:27:19.927 stepwiseDrawing[5334:1a03] time difference was 281
:27:20.202 stepwiseDrawing[5334:1a03] time difference was 274
:27:20.460 stepwiseDrawing[5334:1a03] time difference was 259
:27:20.743 stepwiseDrawing[5334:1a03] time difference was 283
:27:21.011 stepwiseDrawing[5334:1a03] time difference was 268
:27:21.281 stepwiseDrawing[5334:1a03] time difference was 270
:27:21.563 stepwiseDrawing[5334:1a03] time difference was 282
:27:21.848 stepwiseDrawing[5334:1a03] time difference was 284
:27:22.126 stepwiseDrawing[5334:1a03] time difference was 278
:27:22.398 stepwiseDrawing[5334:1a03] time difference was 272
:27:22.677 stepwiseDrawing[5334:1a03] time difference was 279
:27:22.970 stepwiseDrawing[5334:1a03] time difference was 293
:27:23.258 stepwiseDrawing[5334:1a03] time difference was 288
:27:23.545 stepwiseDrawing[5334:1a03] time difference was 287
:27:23.834 stepwiseDrawing[5334:1a03] time difference was 289
:27:24.122 stepwiseDrawing[5334:1a03] time difference was 288
:27:24.413 stepwiseDrawing[5334:1a03] time difference was 292
:27:24.708 stepwiseDrawing[5334:1a03] time difference was 295
:27:25.002 stepwiseDrawing[5334:1a03] time difference was 294
:27:25.303 stepwiseDrawing[5334:1a03] time difference was 301
:27:25.585 stepwiseDrawing[5334:1a03] time difference was 282
:27:25.880 stepwiseDrawing[5334:1a03] time difference was 294
:27:26.174 stepwiseDrawing[5334:1a03] time difference was 294
:27:26.470 stepwiseDrawing[5334:1a03] time difference was 296
:27:26.475 stepwiseDrawing[5334:1a03] time difference was 5
:27:26.777 stepwiseDrawing[5334:1a03] time difference was 302
:27:27.077 stepwiseDrawing[5334:1a03] time difference was 299
:27:27.373 stepwiseDrawing[5334:1a03] time difference was 297
最佳答案
首先让我说这是一个有趣的谜题。我在这方面工作很开心。很好的问题和很好的示例代码。
这是我对可能的答案的看法:
我看到的问题如下。 CGLayer 非常适合重复绘制,因为它们将渲染缓存到平面图像中。当附加操作附加到上下文时,缓存将失效。发生这种情况时,CGLayer 会再次渲染。速度变慢的原因是代码维护了一个 CGLayer (offscreenPrefabCGL),它在 paintActualGutsOfHugeImage 循环的每次迭代中都修改了上下文。由于 offscreenPrefabCGL 的 上下文中的操作序列随着每朵花的增长而增长,因此每次渲染都需要更多时间。这解释了每次显示的时间增加。
我看到两个解决方案:
我实现了 (2) 并取得了良好的效果。前 100 朵花更快,然后它会在 120 毫秒内稳定下来(在设备中)。我用多达 2000 朵花测试了我的修改版本。
我的修改版本在:
http://dl.dropbox.com/u/9866261/felz_mod_stepwiseDrawingV2.zip
关于iphone - run loop/drawRect 中神秘的 "progressive slowing"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4786754/
我认为这样的表达式会导致 Haskell 永远评估。但是 GHCi 和编译程序中的行为让我感到惊讶。 例如,在 GHCi 中,这些表达式一直阻塞到 I Control+C ,但不消耗 CPU。看起来像
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
如果可以的话,我想减少这段代码: class Alarm { internal static void isGreaterThanOrBelowValue(int min, int max,
我有以下问题: 我想创建一个批处理文件,循环访问一定数量的 IP 地址,以停止远程 PC 上的某个服务。 因为停止过程需要一些时间,所以我需要第二个循环来查询服务的状态并等待,直到服务达到“已停止”状
我已经完整地编写了“The Rust Programming Language”在线书籍中的程序,chapter 2 .我还进一步开发了它:通过添加一个简单的问题/响应,用户可以通过输入“y”再次玩游
这个人已经困扰了我一阵子了, 我们应该如何在集合中存储值或在for循环中映射? (let [s #{}] (for [ i (range 10) j (range 1
mov ecx, 16 looptop: . . . loop looptop 这个循环会执行多少次? 如果 ecx
我似乎无法找到一种在 Xtend 中表达以下内容而不诉诸 while 循环的好方法: for(int i = 0; i range(int stop) { range(0, stop) }
好吧,长话短说,我正在学习汇编,我正在尝试循环打印出 ascii 字符“0”-“9”。因此,我完成了我在示例中看到的所有基础知识,例如使用 pushad 和 popad 保存寄存器状态,分配堆栈空间,
我正在尝试为自己编写一个扑克计算器,我有一个 5 级深的 for 循环。 为此,我将 for 循环一个接一个地嵌套。我正在寻找一种方法来简单地使用一个循环(或函数),它可以告诉我想去多少层。对于这个例
我有一本包含约 150,000 个键的字典。没有重复的键。每个 key 的长度为 127 个字符,每个 key 在 1-11 个位置上有所不同(大多数差异发生在 key 的末尾)。每个键的值是一个唯一
我正在尝试编写一个 Lisp 程序来实现与点和方 block 非常相似的棋盘游戏,这意味着我有两个玩家相互竞争但可以连续移动。我正在尝试实现最简单的 minimax 算法来实现这一点,没有 alpha
下面是我实现的代码的简要说明。 for 循环的复杂度应该是 O(n)。我只是无法弄清楚内部 while 循环的时间复杂度。 int x,n; // Inputted by the user.
我目前正在尝试使用 html 分词器 https://godoc.org/golang.org/x/net/html . 所以我想做的是:从 url 获取所有链接,如果 url 包含特定字符串 ->
我有 32 个文件(以相同的模式命名,唯一的区别是下面写的 $sample 编号)我想分成 4 个文件夹。我正在尝试使用以下脚本来完成这项工作,但该脚本无法正常工作,有人可以帮我使用以下 shell
我必须根据 where 条件在我的内部表上做一个循环,但根据我的程序模式,必须在运行时修改 where 条件的字段。 我知道在 SELECT 语句中这是可能的,但是当我在循环中执行此操作时出现错误。
我正在学习关于kdb数据库的q。我担心q中没有循环。 我需要写一个算法,用像C这样的冗长程序在几个嵌套的for循环中编写。但是在q中,我被无法循环的事实所困扰。 仅举一个具体的例子(很多),我有一个简
我不明白为什么这段代码只循环一次然后退出? 在 Ghci 中,我只能回答第一个循环,然后似乎变量 cont 设置为 false 并且我没有提示回答。 结果是: *Main> testLoop1 td1
我正在 Racket 中运行 for 循环,对于列表中的每个对象,我想执行两件事:如果该项目满足条件,(1) 将其附加到我的新列表中,(2) 然后打印列表。但我不知道如何在 Racket 中执行此操作
我正在尝试使用 matlab 并行包中的 parfor 循环。我和这个人有类似的问题:MATLAB parfor slicing issue? 。输出矩阵似乎没有被识别为切片变量。在我的具体情况下,我
我是一名优秀的程序员,十分优秀!