My apologize for asking a basic question but I really could not find a suitable answer for this. I have inherited a C++ code where a part of it has a 2D allocation function Allocate2D
in the form of:
float** Allocate2D(long long sizeX, long long sizeY)
{
float** p = new float*[sizeY];
p[0] = new float[sizeX*sizeY];
for (long long z = 0; z < sizeY; z++) {
p[z] = p[0] + z * sizeX;
}
return ptr;
}
int main(){
long long nX = ... ;
long long nY = ... ;
short** A = (short **)Allocate2D(nX, nY);
// do stuff with A ...
}
I have two questions on this:
1- Is Allocate2D
creating a 2D array with size sizeX
x sizeY
?
2- Is this common/legal/good practice to allocate a 2D short
array such as A
when Allocate2d
is defined for float**
?