Original Post
This is a function called from within a constructor to allocate memory that I wish to access via a 2d array (ie, a square matrix). AlphaMatrix is a pointer to pointers (an array of pointers).
void BuildAlpha()
{
const int sizeAlpha = this->NumberOfParameters;
const int sizeAlphaArray = this->NumberOfParameters * this->NumberOfParameters;
// we dedicate sufficient memory to hold all of our alpha matrix
float * tempAlpha = new float[sizeAlphaArray];
// we make a pointer to pointers
this->AlphaMatrix = new float * [sizeAlpha];
// now we make our pointers point where they must
for(int index = 0; index < sizeAlpha; index++)
{
this->AlphaMatrix[index] = tempAlpha + index * sizeAlpha;
}
}
When this function ends, the pointer tempAlpha no longer exists. The memory is pointed to only through my Array of pointers. How can I then release all this memory when I am done with it?
I know the simple answer is to just use managed code, but this is a time critical part of my applictation.