Original Post
🔒 Locked
Allocating a 3D array
Advertisement
Quote:
Original post by RDragon1
or boost::multi_array ?
/sign
That said...
Cell *** Cells;Cells = new **Cell[ x_size ];for ( size_t x = 0 ; x < x_size ; ++x ) { Cells[x] = new *Cell[ y_size ]; for ( size_t y = 0 ; y < y_size ; ++y ) { Cells[x][y] = new Cell[ z_size ]; }}//access via Cells[X][Y][Z]Alternatively, a single array may work better:
Cell * Cells = new Cell[ x_size * y_size * z_size ];//access via Cells[X + Y*x_size + Z*y_size*x_size]
If you're going to use raw arrays, consider organizing it like this, instead;
or, IMO, better:
Cell*** cells = new Cell**[depth];for( std::size_t z = 0; z < depth; ++z ){ cells[z] = new Cell*[height]; for( std::size_t y = 0; y < height; ++y ) { cells[z][y] = new Cell[width]; }}or, IMO, better:
Cell* cells = new Cell[ width * height * depth ];//to access:cells[ (z * height*width) + (y * width) + x ];Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement