Memory Access Exceedingly Slow For a Simple Loop Through an Array
I am taking about 50 times as long as expected to loop through a simple assignment. My first reaction was that I had disordered my memory access in the arrays, resulting in cache misses. This doesn't seem the case, however.
The pixel value assignm开发者_如何学Pythonent and updating the arrays takes a dogs age. Do any one of you folks have an inclining as to why this is happening? (I am compiling for an iPod with an A4)
memset(columnSumsCurrentFrameA, 0, sizeof(unsigned int) * (_validImageWidth/numSubdivisions) );
memset(rowSumsCurrentFrameA, 0, sizeof(unsigned int) * (_validImageHeight/numSubdivisions) );
int pixelValue = 0;
int startingRow = 0;
int startingColumn = 0;
for (int i = 0; i < _validImageHeight/numSubdivisions; i++)
{
    int index = (i + startingRow) * _imageWidth;
    for( int j = 0; j < (_validImageWidth/numSubdivisions); j++)
    {
        pixelValue = imageData[index + startingColumn + j];
        columnSumsCurrentFrameA[j] += pixelValue;           
        rowSumsCurrentFrameA[i] += pixelValue;              
    }
}
The result of _validImageWidth/numSubdivisions must be an integer, are you sure that is always the case?
Also, you should calculate _validImageWidth/numSubdivisions before entering the double loops, it's not safe to assume your compiler takes care of it.
int limit = _validImageHeight/numSubdivisions;
for (int i = 0; i < limit; i++)
{
        int index = (i + startingRow) * _imageWidth;
        for( int j = 0; j < limit; j++)
        {
            pixelValue = imageData[index + startingColumn + j];
            columnSumsCurrentFrameA[j] += pixelValue;           
            rowSumsCurrentFrameA[i] += pixelValue;              
        }
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论