Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c dispatch_async比performSelectorInBackground慢:?_Objective C_Ios_Multithreading_Cocoa Touch_Grand Central Dispatch - Fatal编程技术网

Objective c dispatch_async比performSelectorInBackground慢:?

Objective c dispatch_async比performSelectorInBackground慢:?,objective-c,ios,multithreading,cocoa-touch,grand-central-dispatch,Objective C,Ios,Multithreading,Cocoa Touch,Grand Central Dispatch,在我的应用程序中,我使用performSelectorInBackground:从磁盘加载图像。在使用dispatch_async进行了一些单元测试之后,我决定用dispatch_async调用替换performSelectorInBackground dispatch_queue_t currentBackgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_async(curren

在我的应用程序中,我使用
performSelectorInBackground:
从磁盘加载图像。在使用dispatch_async进行了一些单元测试之后,我决定用dispatch_async调用替换performSelectorInBackground

dispatch_queue_t currentBackgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(currentBackgroundQueue, ^{
    [self getImageFromDisk:sPath delegate:(id)delegate];
});
代码似乎可以工作,但现在我的图像加载速度比以前慢。当用户滚动图像时,这会导致黑色图像


我的应用程序包含某种photoscroller。我不能使用苹果的平铺示例代码,因为它将应用程序的大小增加了很多。我使用snippet从磁盘加载映像。

我以前在其他类似问题上说过,在全局队列上使用dispatch async将导致类似同步的行为,特别是对于最终更新UI的代码。但当我尝试它时,它的结果或多或少与同步调用相同。创建并使用您自己的队列,或(创建并使用您自己的队列)执行NSO操作

我认为这样做的原因是,即使代码在技术上是异步的,发布到全局队列的任何事件都将占用队列的处理时间。不要将全局队列用于后台操作


使用自定义队列并启动自己的runloop。

太好了,谢谢。我创建了一个自定义队列,效果很好!