Fastest way to read/store lots of multidimensional data? (Java)

前端 未结 5 1374
萌比男神i
萌比男神i 2021-01-02 18:14

I have three questions about three nested loops:

for (int x=0; x<400; x++)
{
    for (int y=0; y<300; y++)
    {
        for (int z=0; z<400; z++)
          


        
5条回答
  •  粉色の甜心
    2021-01-02 18:34

    Have you tried this:

    Object[][][] store = new Object[ 400 ][300][400];
    
    for (int x=0; x<400; x++)
    {
        Object[][] matrix = store[x];
    
        for (int y=0; y<300; y++)
        {
            Object[] line = matrix[y];
            for (int z=0; z<400; z++)
            {
                 // compute and store value
                 line[z] = // result;
            }
        }
    }
    

    it might improve your cache thrashing.

提交回复
热议问题