Long running calculation on background thread

Posted by SundayMonday on Game Development See other posts from Game Development or by SundayMonday
Published on 2012-10-22T01:06:14Z Indexed on 2012/10/22 5:17 UTC
Read the original article Hit count: 243

Filed under:

In my Cocos2D game for iOS I have a relatively long running calculation that happens at a fairly regular interval (every 1-2 seconds). I'd like to run the calculation on a background thread so the main thread can keep the animation smooth.

The calculation is done on a grid. Average grid size is about 100x100 where each cell stores an integer. Should I copy this grid when I pass it to the background thread? Or can I pass a reference and just make sure I don't write to the grid from the main thread before the background thread is done?

Copying seems a bit wasteful but passing a reference seems risky. So I thought I'd ask.

© Game Development or respective owner

Related posts about objective-c