I have to create a 3-Dimensional array, wich gets allocated at object creation. I’ve done such stuff before with normal arrays.
typedef unsigned char byte; // =|
byte ***data;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re using
C++, I strongly advise you usingstd::vectorinstead of raw arrays.Something like:
Will create a 3x3x3 array of
chars, all initialized to0.You can then access the items the same way you would with a
char***:Depending on your needs you might also use only one
std::vectorand inline your three-dimensional space into it. This would fasten both computation and copy operations, as the values would then be in a contiguous block of memory.The way you could inline the values depending on your needs, but here is an example:
For a 3 dimensional array like this:
You might store values like this in memory:
This require some maths, but if you encapsulate this, you can even achieve the same level of usability of a
vectorofvectorofvector, with much higher performances.