NSOperationQueue vs NSThread Priority——控制 NSOperationQueue 消耗多少 cpu
我需要异步预加载一些纹理和声音效果,以便在我正在开发的 iOS 游戏中创建流畅的用户体验。
我试图在 NSOperationQueue 和 NSThread 之间做出决定,以在游戏过程中加载这些游戏资源。
NSOperationQueue 似乎是一个明显的赢家,并且有很多好处,但我担心对这个“后台”资源加载任务进行有效的优先级控制,以便我可以根据它消耗的周期数来降低它,以免影响帧率。
我看到 NSOperationQueue 有一个“优先级”的概念,但它看起来与 NSThread 的“优先级”概念不同。如果我错了,请纠正我,但 NSThread 的优先级与系统上运行的其他线程相关,而 NSOperation 的优先级是该任务相对于其他排队任务的优先级。
我想知道的是......
有没有一种方法可以控制给定 NSOperationQueue 任务的优先级,以及与当前运行的其他线程相比,它可以消耗多少个周期(而不是相对优先级与其他排队任务)在设备上?
在 NSOperationQueue 的任务中更改当前线程的优先级是否安全? (使用 NSThread 的 +setPriority)
I have some textures and sound effects preloading I need to do asynchronously to create a smooth user experience in an iOS game I am developing.
I am trying to decide between NSOperationQueue and NSThread to load these game resources during gameplay.
NSOperationQueue seems to be a clear winner and have numerous benefits, but I'm concerned about having effective priority control over this 'background' resource loading task, so that I can turn it down in terms of how many cycles it consumes so as not to affect frame-rates.
I see that NSOperationQueue has a concept of 'priority', but it looks different than NSThread's concept of 'priority'. Correct me if I'm wrong, but NSThread's priority is in relation to other threads running on the system, and NSOperation's priority is the priority of that task in relation to the other queued tasks.
What I want to know is....
Is there a way to control the priority of a given NSOperationQueue task in relation to how many cycles (as opposed to relative priority vs. other queued tasks) it can consume compared to other threads currently running on the device?
Is it safe within an NSOperationQueue's task to change the current thread's priority? (with NSThread's +setPriority)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSOperation 的实例还有一个“setThreadPriority:”方法以及“setQueuePriority:”。
这绝对是您正在寻找的。
An instance of NSOperation also have a 'setThreadPriority:' method, along with 'setQueuePriority:'.
This is definitively what you are looking for.