C++ Mex File Clear All Memory and Dynamic Memory
Mostrar comentarios más antiguos
I have a C++ mex file that takes a raw data signal of varying length as an input. I noticed a memory leak and I believe it is due to not clearing the dynamic memory such as 'rawdata'. I pasted a gutted outline of the code I am using below.
When I try to delete 'rawdata' as shown below, it crashes Matlab. Does anyone have any recommendations of how I should clear the variable 'rawdata'?
Better yet, is there a command to clear all variables from memory after a mex function runs to completion? (Such as the matlab 'clear all') Is there a way to better trouble shoot a memory leak and determine which variable it is coming from?
void main(double *rawdata) { delete[] rawdata; rawdata = 0x0; }
/* The gateway function */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
double *rawdata;
rawdata = mxGetPr(prhs[0]);
/* assign a pointer to the output */
main(rawdata);
}
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!