Re: drawing an array of pixels to the screen
Re: drawing an array of pixels to the screen
- Subject: Re: drawing an array of pixels to the screen
- From: John Stiles <email@hidden>
- Date: Mon, 12 Nov 2007 14:39:34 -0800
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:
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:
This email sent to email@hidden