A program I've written needs to check millions of points in a 2D array to see if they are not null. Here is the code I am using:
Particle *particleGrid[1920][1080];
bool Sensor::checkForParticle(int x, int y) {
if (x > 1920 || x < 0) return 0;
if (y > 1080 || y < 0) return 0;
if (mainController->particleGrid[x][y] != NULL) {
return 1;
}
return 0;
}
This function uses the most CPU in the entire application (~70% of the application's CPU usage is due to this function), even more than my implementation of the Bresenham line drawing algorithm (the example function is called on every point of the line generated by the Bresenham algorithm). Is there a more CPU-efficient way to perform the null-checking operation?
x >= 1920andy >= 1080