Re: Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
Re: Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
- Subject: Re: Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
- From: vincent habchi <email@hidden>
- Date: Wed, 7 Jul 2010 09:51:39 +0200
Le 7 juil. 2010 à 09:33, Graham Cox a écrit :
>
> On 07/07/2010, at 3:59 PM, vincent habchi wrote:
>
>> - (void)drawPoint:(CGContextRef)ctx origin:(CGPoint)origin dimension:(int)dim data:(double **)data {
>> double pt [dim];
>>
>> for (int i = 0 ; i < dim ; i ++, *data ++) {
>> memcpy (& (pt [i]), * data, sizeof (double));
>> }
>
>
> I have to ask - why are you doing a copy here, and in such an inefficient way too? Your data already is an array of doubles, why do you need to convert to another one? Also, why the double indirection?
The double indirection is necessary in order for the master data pointer (*data) to progress through the data chunk; since that chunk can hold different items, I have to decode it on the fly and call the appropriate method that interprets an appropriate block of data. If I were using a '(double *)data' instead, I would end up incrementing a local copy, and the main pointer in the caller method would not be altered. Or am I mistaken?
But, basically you're right about the copy. This might be more canonical:
[foo point:NSMakePoint (* data, * (data + 1))];
* data += dim;
Thanks for pointing me out this, as always, your comments are *really* helpful
Vincent_______________________________________________
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