Mail Archives: djgpp/1999/06/23/05:52:12
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 -