I have an NSMutableArray
that's accessed primarily by the main thread in my iOS game. Every 2-3 seconds I need to perform an expensive operation on this grid. I don't need to modify the grid. I just need to do some calculations and return a result. How can I efficiently and safely use the grid in a background thread?
So far I've considered just copying the grid and passing it as the object in performSelectorInBackground
. However this seems potentially wasteful. I've also considered just accessing the grid's reference from the background thread and making sure the main thread doesn't write to the grid until the background thread has finished processing. However this feels risky and I'm not sure if it's a common practice.