Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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
Ios 以极低的优先级执行代码_Ios_Multithreading_Performance_Cocoa Touch_Game Center - Fatal编程技术网

Ios 以极低的优先级执行代码

Ios 以极低的优先级执行代码,ios,multithreading,performance,cocoa-touch,game-center,Ios,Multithreading,Performance,Cocoa Touch,Game Center,我知道在后台做某事的两种方法 1: 两种方法都帮不了我。我正在向游戏中心报告玩家的游戏分数,当我这样做时,像iPod4G这样的旧设备的游戏性明显滞后。但是没有真正的匆忙。是否有可能使此代码在CPU利用率较低的情况下执行?我在游戏结束后做,但用户可以立即重新启动游戏,他会看到大约2秒的小延迟 分数报告代码: - (void) reportScore:(int64_t)score forLeaderboardID:(NSString*)category newBestTime:(BOOL)newBe

我知道在后台做某事的两种方法

1:

两种方法都帮不了我。我正在向游戏中心报告玩家的游戏分数,当我这样做时,像iPod4G这样的旧设备的游戏性明显滞后。但是没有真正的匆忙。是否有可能使此代码在CPU利用率较低的情况下执行?我在游戏结束后做,但用户可以立即重新启动游戏,他会看到大约2秒的小延迟

分数报告代码:

- (void) reportScore:(int64_t)score forLeaderboardID:(NSString*)category newBestTime:(BOOL)newBestTime {
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
    scoreReporter.value = score;
    scoreReporter.context = 0;
    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
      //nothing here
    }];
}

使用低优先级队列:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  ...
});

只是另一个建议,我不确定它是否有效:

-(void)lowPriorityThread {
    NSBlockOperation *b = [NSBlockOperation blockOperationWithBlock:^{
        //your code
    }];

    b.queuePriority = NSOperationQueuePriorityVeryLow;

    [[NSOperationQueue currentQueue] addOperation:b];
}

我看不出调度队列优先级默认、调度队列优先级低和调度队列优先级低在性能上有什么区别_BACKGROUND@user1561346这将取决于负载;如果设备不忙,您不会注意到任何差异。CPU和GPU利用率低于50%。但是我可以在分数报告中看到帧下降。@user1561346当使用低优先级队列时?如何报告分数?@user1561346方法
reportScoreWithCompletionHandler
意味着它异步运行,因此调用该代码的线程的优先级无关紧要。这就是你需要关注的地方。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  ...
});
-(void)lowPriorityThread {
    NSBlockOperation *b = [NSBlockOperation blockOperationWithBlock:^{
        //your code
    }];

    b.queuePriority = NSOperationQueuePriorityVeryLow;

    [[NSOperationQueue currentQueue] addOperation:b];
}