views:

60

answers:

2

Hi there, I've got an game app displaying a lot of images that need to be processed before being displayed. The set of images need to be refreshed with new ones every 2 seconds.

to speed up the display : While the first set of images is displayed, I'd like to prepare in background the next set.

I've got a specific class "board" that I could call in background to generate the "nextSet" while "currentSet" is being used by the player.

What is the best way to do it ?

Threads seems to be the thing to do ... is yes, do where may I find some examples of code triggering that generation in background ?

cheeerio,

Tibi.

A: 

This Threading Cocoa tutorial is good enough to start. They also have sample code

For the question: should you use NSThread.

Technically, yes, you should. For heavy IO like this, perform on the background will not freze your UI and it will improve your User Experience as well. But, be careful when using thread, it has its difficulty like data sharing, deadlock...

vodkhang
+1  A: 

Sounds like a producer/consumer situation. I suggest you look at queues to solve this. You would have one thread processing images in the background (producer) and placing then in the queue. Then you have your UI that consumes them when they are ready by showing them to the user. In iOS4 there is enhanced support for concurrency related tasks and Apple have some excellent guides on the topic.

Concurrency Programming Guide
Grand Central Dispatch

Good luck

willcodejavaforfood