delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/23/05:52:12

Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE301468967@probe-2.acclaim-euro.net>
From: Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: Short pointers to Allegro Bitmaps?
Date: Wed, 23 Jun 1999 10:51:25 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.0.1460.8)
Reply-To: djgpp AT delorie DOT com

S Prasad writes:
> short *SPtr;			//Short pointer to an offscreen bitmap
> SPtr = &((short*)OffScreen->line[Y])[X];  //Assign the pointer a value
>							//in the OffScreen
BITMAP
>				   
> Now, in an inner loop, i have this code:
>
> *SPtr = ((short*)Texture->line[Y])[X];
>
> Is there any way I can avoid casting to short* EACH time through the
> loop?

You've already done that in the line at the top of your post, when
you initialise SPtr from Offscreen->line[Y]. If you leave off the [X]
part of this, then you can just index directly into SPtr to get the
various pixels within the line, eg. SPtr[0], SPtr[1].

This doesn't make any difference in performance terms, though: it
just helps to make your code easier on the eye. The compiler doesn't
actually generate any code when you cast a pointer to a different 
type. This is telling it what size of data it should transfer when
you later dereference the pointer, but doesn't affect anything 
directly, so there is no performance difference between dereferencing
a pointer of type A versus casting a pointer of type B to type A and
then dereferencing it.


	Shawn Hargreaves.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019