Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing an array of pixels to the screen



Yes, you're correct. If you declare the array as
	int a[10][10];

Then really 'a' is a 100-element array and [Y][X] is syntactic sugar for doing a[Y*10+X];

But if you declare the array as
	int **a;

Then [Y][X] does two memory lookups. First it looks up a[Y] and assigns it to a temporary (let's call it TEMP), and then it does a second lookup to find TEMP[X].
This is getting pretty far off-topic, though, since none of this is specific to ObjC.


On Nov 12, 2007, at 2:17 PM, David Spooner wrote:

On 12-Nov-07, at 2:11 PM, John Stiles wrote:

The generated code is the same. The [][] syntax is simply syntactic sugar which hides the multiplication.

I believe this is only true when the array dimensions are known. For T a[H][W], a[y][x] is effectively *(a + y*W + x), but for T **a, a[y][x] is *(*(a + y) + x). Of course there is multiplication implicit in the pointer arithmetic...



On Nov 12, 2007, at 12:58 PM, Jason Horn wrote:

Dave,

Thanks for your input. Wouldn't something like array[x + y *width] be slower than array2d[x][y] when you are iterating over a large image? Does the extra multiplication operation slow you down?

- Jason

I am not concerned by the multiplication, but I don't claim to be an expert in things optimal...


dave

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/jstiles% 40blizzard.com


This email sent to email@hidden

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >drawing an array of pixels to the screen (From: Jason Horn <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: John Stiles <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: Jason Horn <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: Jean-Daniel Dupas <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: David Spooner <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: Jason Horn <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: John Stiles <email@hidden>)
 >Re: drawing an array of pixels to the screen (From: David Spooner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.