On Jul 8, 2013, at 18:04 , Jens Alfke <j...@mooseyard.com> wrote: > > On Jul 7, 2013, at 1:37 PM, Frederick Bartram <bartr...@acm.org> wrote: > >> Have you tried using NSData to store C-arrays? > > Or alternatively use NSPointerValue to wrap a pointer to a malloc’ed C array > as an object.
It seems to me that an array of float is worth a dedicated object, for example MPWRealArray, SMUGRealVector or the arrays in FScript: @interface MPWRealArray : MPWObject { NSUInteger capacity; NSUInteger count; float *floatStart; } This is really easy to create yourself, the key insight is that you don't have to use the pre-defined objects that Apple gives us, especially when performance is a concern you are frequently better of rolling your own. I benchmarked this a little while ago, and creation a 10000 element real array was 1000 (one thousand) times faster than creating a 10000 element NSArray of (float) NSNumbers. It also uses 5-10 times less memory, and if needed you can define homogenous operations on the array, using tight C loops or the Accelerate framework. For example, summing such an array can be done as follows: -(float)vec_reduce_sum { float theSum=0; vDSP_sve ( floatStart, 1, &theSum, count ); return theSum; } That's roughly 200 times faster than summing an NSArray of NSNumber. Cheers, Marcel https://github.com/mpw/MPWFoundation https://bitbucket.org/liscio/smugmath/ http://www.fscript.org _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com