• 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: drawing an array of pixels to the screen
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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>)

  • Prev by Date: return pointer to a 2d aray
  • Next by Date: Re: Change a NSMenu's shape?
  • Previous by thread: Re: drawing an array of pixels to the screen
  • Next by thread: Re: drawing an array of pixels to the screen
  • Index(es):
    • Date
    • Thread