Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between CFArray and NSArray

I'm looking for an easier way to manipulate audio buffers on the iPhone. Mainly I'm trying to avoid pointer issues and array count issues with C, but don't want to be slowed down by number objects like NSNumber or NSInteger which I would have to use with NSArray.

I've come across CFArray which seems like it might be a nice middle ground. Am I correct in this assumption? Or am I missing something?

like image 441
Eric Brotto Avatar asked Dec 06 '22 16:12

Eric Brotto


2 Answers

Not really. CFArray is basically the same as NSArray, you can even cast between the two, this is called toll-free bridging.

CFArray (and its mutable counterpart) does allow you to specify your own callback functions for retaining and releasing the objects (pointers) in your array, which would allow you to store arbitrary pointers (not just NSObjects) in the array and implement your own memory management scheme, but I doubt that this would result in any real performance gains. For your use case, C arrays are probably the way to go.

like image 156
omz Avatar answered Dec 17 '22 10:12

omz


If performance and memory size are of any concern, which they likely will be for real-time audio processing, stick to plain C arrays, and learn how to code array passing and access correctly.

You need to handle audio in C arrays anyway, as the iOS Audio Queue and Audio Unit APIs pass audio data using C arrays.

like image 33
hotpaw2 Avatar answered Dec 17 '22 09:12

hotpaw2