Now, I have the 4 above variables in my watches window. It seems that Vert and Vertic form arrays, but Ver and Vertices do NOT.
That is just a property of the Watch window it does not mean that the memory has not been allocated.
The watch window has to display the variables by their type Ver and Vertices are of type T ** i.e. pointers to pointers and Vert and Vertic are type T[][] i.e. 2D arrays. The watch window does not know how much memory you have allocated to Ver and Vertices so can not display the as an array.
Also remember that in the array Vertic the memory for Vertic[1][0] is contiguous with Vertic[0][4] (that is there are right next to each other) however with Ver the same is not true Ver[1][0] is like to not be contiguous with Ver[0][4] (although there is a small chance it will be).
I note on declaring variable multi-dimensional arrays, I almost never use this method
-
float** Ver; // Init Ver as a pointer to a pointer to a float
-
Ver = new float* [2]; // Init Ver as a pointer to a float array of size 2
-
Ver[0] = new float[5]; // Init Ver[0] as a float array of size 5
-
Ver[1] = new float[5];
-
I would do it like this
-
float *Ver; // Init Ver as a pointer to a float
-
Ver = new float[2*5]; // Init Ver a float array of size 2 * 5 = 10
-
There are 2 main reasons.
1. The allocation is much simpler, 1 single allocation and deallocation much much easier to handle and get right.
2. The memory is allocated in the same pattern to what you get if you actually declare a static 2 dimensional float array. Because of this it is much easier to slip this allocation in place instead of a statically declared array. You have less chance that a surupticious memset somewhere will go wrong since you know your array memory is contiguous.
I would then use access it as
Ver[y * MAX_X + x];
This can be encapsulated in a function or class to make it easier.
There are other possibilities, a hybred for instance where you allocate an array of pointers to pointers and a contiguous block of memory and the initialise your array to point at the correct locations in the contiguous block. This has the all advantages of both approaches will out too much overhead.
-
float **Ver; // Init Ver as a pointer to a float
-
Ver = new float *[2]; // Init Ver a float array of size 2 * 5 = 10
-
-
Ver[0] = new float[2*5];
-
Ver[1] = Ver[0] + 5;
-
Only 2 allocations for any size array, memory is contiguous and can be treated like a statically allocated array. Can use C symantecs for accessing a 2D array.