Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiency of iteration: NSArray vs C array of pointers?

I'm working at the audio buffer level, mixing audio signals created by a colleciton of objects. Since I'm looping through these objects at 44.1khz, efficiency is crucial. Is there any difference in the efficiency of iterating over an NSArray vs a C array of pointers? How about NSMutableArray?

like image 225
morgancodes Avatar asked Feb 26 '26 22:02

morgancodes


1 Answers

Is there any difference in the efficiency of iterating over an NSArray vs a C array of pointers?

Yes. Iterating directly over a C array will be faster.

Most apps don't need to worry about this and should look elsewhere for performance gains. But if, in your app, this function runs 44,100 times per second, you probably should micro-optimize it (after, of course, making sure that it does as little as possible—that is, only the things you absolutely need to do 44,100 times per second).

How about NSMutableArray?

Vs. an NSArray? No difference that you can rely on or should care about.

like image 165
Peter Hosey Avatar answered Feb 28 '26 11:02

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!