• Create Account

#ActualServant of the Lord

Posted 31 December 2012 - 10:29 PM

It looks like (correct me if I'm wrong), that you're not using a 2D array at all.

Instead, you're using a vector of vectors, which is not a 2D array (it's an array of arrays). C++ doesn't have a built-in 2D vector.

Trying to massage a 'array of arrays' to behave like a 2D array is unnecessary labor. There are two far superior options:

1. Use a 3rd party class (or make one yourself) that actually is a 2D array.
2. Treat a 1D array (like std::vector) as a 2D array.

I usually go with the second option because it's so easy. Memory in RAM is one dimensional. 2D arrays would just line up a extra large 1D array of memory, and do some math to convert 2D coordinates to 1D coordinates. The math is very easy:

std::vector<Type> myArray(width * height);

int index = (y * width) + x;
myArray[index] = value;

Easy as pie. Here's the math explanation.

#2Servant of the Lord

Posted 31 December 2012 - 10:29 PM

It looks like (correct me if I'm wrong), that you're not using a 2D array at all.

Instead, you're using a vector of vectors, which is not a 2D array (it's an array of arrays). C++ doesn't have a built-in 2D vector.

Trying to massage a 'array of arrays' to behave like a 2D array is unnecessary labor. There are two far superior options:

1. Use a 3rd party class (or make one yourself) that actually is a 2D array.
2. Treat a 1D array (like std::vector) as a 2D array.

I usually go with the second option because it's so easy. Memory in RAM is one dimensional. 2D arrays would just line up a extra large 1D array of memory, and do some math to convert 2D coordinates to 1D coordinates. The math is very easy:

std::vector<Type> myArray(width * height);

int index = (y * width) + x;
myArray[index] = value;

Easy as pie. Here's the math explanation.

#1Servant of the Lord

Posted 31 December 2012 - 10:29 PM

It looks like (correct me if I'm wrong), that you're not using a 2D array at all.

Instead, you're using a vector of vectors, which is not a 2D array (it's an array of arrays). C++ doesn't have a built-in 2D vector.

Trying to massage a 'array of arrays' to behave like a 2D array is unnecessary labor. There are two far superior options:

1. Use a 3rd party class (or make one yourself) that actually is a 2D array.

2. Treat a 1D array (like std::vector) as a 2D array.

I usually go with the second option because it's so easy. Memory in RAM is one dimensional. 2D arrays would just line up a extra large 1D array of memory, and do some math to convert 2D coordinates to 1D coordinates. The math is very easy:

std::vector<Type> myArray(width * height);

int index = (y * width) + x;
myArray[index] = value;

Easy as pie. Here's the math explanation.

PARTNERS