"Single NSMutableArray" vs. "Multiple C-arrays" --Which is more Efficient/Practical?
Situation:
I have a DAY structure. The DAY structure has three variables or attributes: a Date (NSString*), a Temperature (float), and a Rainfall (float).Problem:
I will be iterating through an array of about 5000 DAY st开发者_JAVA技巧ructures and graphing a portion of these onto the screen of the iPhone device using OpenGL.Question:
As far as drawing performance, which is better? I could simply create an NSMutableArray of DAY structures (NSObjects) and iterate on the array on each draw call -- which I think would be hard on the CPU. Or, I could instead manually manage three different C-Arrays -- One for the Date String (2-Dimensional), One for the temperature (1-Dimensional) and One for the Rainfall (1-Dimensional). I could keep track of the current Day by referencing the current index of the iterated C-Arrays.Why are you keeping a date in an NSString object instead of an NSDate object?
If it's not a lot of work, always go with the convenient solution and only optimize when the code proves to be a bottleneck. And if you were going to write a big chunk of code that would take a long time to rewrite into a more optimized version, do a simple test case and profile.
Try both and profile.
There's really no other answer, especially since we can never know your exact context for sure. Every app works differently.
If they both give the same performance, choose the one that is the easiest for you to use and is the most readable.
精彩评论