Author Topic: pointers  (Read 2266 times)

0 Members and 1 Guest are viewing this topic.

Offline Storm Trooper

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
pointers
« on: July 21, 2010 »
how do pointers help to give a turbo charge to rendering?
and how do you use them?
say for example, a usual FOR X and Y LOOP.

thanks again,
tR4nt0r

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: pointers
« Reply #1 on: July 21, 2010 »
let's assume you want to fill an image which is simply an array of width*height integers.

instead of adressing each pixel individually, like this:
Code: [Select]
for (y=0; y < height; y++)
{
  for (x=0; x < width; x++)
  {
    adress= y * width + x;
    image[adress] = color;
  }
}

...you just increase your pointer when stepping from one pixel to the next:
Code: [Select]
dest= image;
for (y=0; y < height; y++)
{
  for (x=0; x < width; x++)
  {
    *dest= color;
    dest++;
  }
}

any half-decent compiler will do this optimization automatically for you, though.
Challenge Trophies Won: