I am currently messing around with the sgetrf_ and sgetrs_ functions in the accelerate framework. When returning the solution, these functions overwrite their array parameters. "columnMajorMatrix" in this snippet is overwritten to return the output.
I would like to hang on to that data. Therefore I copy the data into a new array "result" and feed that to sgetrf_. The "result" is returned to the user. Copying of the data is done via malloc and memcpy. However, I have no free equivalent in the code below. In other words, there is a memory leak here. I also don't want to rely on the user to free the allocated memory. As far as I am aware, there is no autorelease equivalent for malloc memory. Is there a way around this?
This snippet is incomplete (with regard to "numberofRows", etc.) , but illustrates the basic problem I want to solve.
I would prefer to use malloc since I don't know in advance how big these arrays can get.
Thanks!
Code:
sgetrf_(&numberofRows, &numberofColumns, columnMajorMatrix, &numberofRows, pivotIndices, &errorCode);
I would like to hang on to that data. Therefore I copy the data into a new array "result" and feed that to sgetrf_. The "result" is returned to the user. Copying of the data is done via malloc and memcpy. However, I have no free equivalent in the code below. In other words, there is a memory leak here. I also don't want to rely on the user to free the allocated memory. As far as I am aware, there is no autorelease equivalent for malloc memory. Is there a way around this?
This snippet is incomplete (with regard to "numberofRows", etc.) , but illustrates the basic problem I want to solve.
Code:
-(float *) solveProblemFor:(float *) columnMajorMatrix
... : ...
{
//copy data
float *result = (float *)malloc(numberofRows*numberofColumns*sizeof(float));
memcpy(&result,columnMajorMatrix,numberofRows*numberofColumns*sizeof(float));
//solve for dataset
....
sgetrf_(&numberofRows, &numberofColumns, result, &numberofRows, pivotIndices, &errorCode);
....
//return solution. And free data?
return result;
}
I would prefer to use malloc since I don't know in advance how big these arrays can get.
Thanks!