Archived

This topic is now archived and is closed to further replies.

Dynamically allocate/deallocate 3 dim array on floats..

This topic is 5870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
The simpliest way is to create a one-dimensional-array. Then you can use a macro to access the element you want or the "()" operator if you use c++.

Share this post


Link to post
Share on other sites
Here''s how I do it with a lil tile engine I''m working on
  
tiles = new Tile **[sizeof(Tile**) * layers];
height_map = new UCHAR *[height];

for(int lyr = 0; lyr < layers; lyr++)
{
tiles[lyr] = new Tile *[sizeof(Tile*) * height];

for(int x = 0; x < height; x++)
{
height_map[x] = new UCHAR [width];
tiles[lyr][x] = new Tile [sizeof(Tile) * width];
}

}

just change the tiles to floats and the UCHAR to float and such

Share this post


Link to post
Share on other sites
Allocation:
float ***controlpoints;
controlpoints = new float**[4];
for(int x = 0; x < 4; ++x)
{
controlpoints[x] = new float*[4];
for(int y = 0; y < 4; ++y)
controlpoints[x][y] = new float[3];
}

Deallocation:
for(int x = 0; x < 4; ++x)
{
for(int y = 0; y < 4; ++y)
// delete innermost arrays
delete [] controlpoints[x][y];
// delete outer inner arrays
delete [] controlpoints[x];
}
// delete outermost array
delete [] controlpoints;

Share this post


Link to post
Share on other sites