• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: The cost of using objects rather than plain C variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The cost of using objects rather than plain C variables


  • Subject: Re: The cost of using objects rather than plain C variables
  • From: Marcel Weiher <email@hidden>
  • Date: Tue, 09 Jul 2013 18:52:28 +0200

On Jul 8, 2013, at 18:04 , Jens Alfke <email@hidden> wrote:

>
> On Jul 7, 2013, at 1:37 PM, Frederick Bartram <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Re: The cost of using objects rather than plain C variables (From: Jens Alfke <email@hidden>)

  • Prev by Date: Creating non-scaling markers like maps
  • Next by Date: Cocoaheads Lake Forest meets this Wednesday, 7/10, at 7pm
  • Previous by thread: Re: The cost of using objects rather than plain C variables
  • Next by thread: Re: The cost of using objects rather than plain C variables
  • Index(es):
    • Date
    • Thread