Fast(est) way to manipulate memory
Hi, I'm trying to get updating the pixels of an image as fast as possible. I'm wondering if there is some C++ magic I can apply to make it faster. Or some other kind of magic...
Right now I'm basically doing like below. The actual loop I use has a more calculations in it.
Code:
for (int y=0;y<height;y++)
{
int yval = width * y;
for (int x=0;x<width;x++)
{
COLOR* color1 = &colors1[yval + x];
COLOR* color2 = &colors2[yval + x];
color1->r = color2->r;
color1->g = color2->g;
color1->b = color2->b;
}
}
I'm looking for something different to make this blazing fast, perhaps something lower level. Do you have any suggestions?
I tested switching to using pointer arithmetic for the color array access but that didn't make much difference.
Right now it takes about 15 milliseconds to update a 2048x2048 image including a few calculations in my loop. It is not a whole lot but if I need to do it several times in one code cycle which I often do then one quickly approaches 1/10th of a second where lag can start to be noticable.