1

I have 2D static array with a size of 256 X 256.

Array[256][256]

Each Array element is storing two integer values.

Now, the issue is that the program in which I am using this array has to be time efficient. But I have noticed that those elements like Array[1][40], Array[34][67] and Array[80][80], they take less time as compared to Array[150][256], Array[140][192]. Thus, the index values greater than 100 takes more time as compared to other.

Is there any other data structure which can help me to achieve constant time access to the value but also takes less time to access

Code:

for( counter1=0; counter1< sizeof(chunk1); ++counter1)
{

    IndexEntries &data=IndexTable[chunk1[counter1]][chunk1[counter1+1]];
    DoubleTableEntries &GetValue=NewDoubleTable[NextState_chunk1][data.index]; 
    NextState_chunk1= GetValue.Next_State;
    ++Bcount;
    buffer[ Bcount]=NextState_chunk1;
    ++counter1;

    //  Code lines skipped
}  

The values of chunk1[counter1] and chunk1[counter1+1] ranges from 0-255. Where chunk1[counter1] and chunk1[counter1+1] is array of random unsigned characters.

15
  • 3
    How do you figure indices greater than 100 take more time to access? Commented Apr 28, 2014 at 8:24
  • @Ben I used chrono time library to measure time. In a for loop, in which I am accessing these elements, I put the timer in the start and end of loop to measure time. Commented Apr 28, 2014 at 8:26
  • An array should be perfect for this. The only effects you could be seeing are due to cache behaviour, this is impossible to determine without seeing your code (it's access pattern dependant). Or you could have a bug in your timing tests. What kind of times are we talking, mS, uS? Commented Apr 28, 2014 at 8:26
  • 1
    Do repeated access to the same element with an index higher than 100 show the same number? If not (successive accesses are faster), then it could be that your data is not cached. Commented Apr 28, 2014 at 8:26
  • @Joe I am using chrono high resolution timer . Using uS Commented Apr 28, 2014 at 8:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.