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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]