Created
October 25, 2014 21:04
-
-
Save enghqii/b00b03b98d6f999f14ce to your computer and use it in GitHub Desktop.
Dynamic 3rd dimension array alloc in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#define SAFE_DELETE_ARRAY(ptr) { if(ptr) { delete [](ptr); (ptr)=NULL; } } | |
int main(){ | |
// alloc 'team' | |
int*** team = new int**[1001]; | |
for(int x = 0; x < 1001; x++){ | |
team[x] = new int*[16]; | |
for(int y = 0; y < 16; y++){ | |
team[x][y] = new int[16]; | |
} | |
} | |
// deal with 'team' | |
// delete 'team' | |
for(int x = 0; x < 1001; x++){ | |
for(int y=0;y<16;y++){ | |
SAFE_DELETE_ARRAY(team[x][y]); | |
} | |
SAFE_DELETE_ARRAY(team[x]); | |
} | |
SAFE_DELETE_ARRAY(team); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
int team[1001][16][16];