Handling Huge Multidimensional Arrays in C++

前端 未结 8 1998
别那么骄傲
别那么骄傲 2021-01-24 19:15

I\'m designing a game in C++ similar to Minecraft that holds an enormous amount of terrain data in memory. In general, I want to store an array in memory that is [5][4][5][50][

8条回答
  •  -上瘾入骨i
    2021-01-24 19:49

    A smaller example (with changed names for all the structs, to make the general principle clearer). The 'Bloe' struct is the one you want to allocate on the heap, and this is accomplished using 'new'.

       struct Bla {
            int arr[4][4];
       };
    
       struct Bloe {
            Bla bla[2][2];
       };
    
       int main()
       {
            Bloe* bloe = new Bloe();
            bloe->bla[1][1].arr[1][1] = 1;
            return 0;
       }
    

提交回复
热议问题