- the mxArray is initialized
- the automated memory management feature is turned on by calling the mlfEnterNewContext and mlfRestorePreviousContext function pair.
Why does my MATLAB C Math Library application run progressively slower?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am writing a program that executes a loop and must run very quickly (each loop must be under
0.001 sec). The slowest part of a function is by far the line:
mlfAssign(&A, mlfDoubleMatrix(numSpikes, 4, listSpikes, NULL));
This line takes longer and longer each time the function is called.
The context of the function call is as follows:
func()
{
mxArray *A;
double listSpikes[..]
...
//Not inside a loop
mlfAssign(&A, mlfDoubleMatrix(numSpikes, 4, listSpikes, NULL));
...
mxDestroyArray(A);
}
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 2009
It is quite likely that the problem you are experiencing is due to memory leaks in your code. Therefore, you can either use the MATLAB C Math Library's automated memory management feature, or use the explicit memory management.
The explicit memory management requires more account keeping. Each time you allocate memory for an mxArray variable (e.g., when you use the mlfDoubleMatrix routine) you have to destroy the array using mxDestroyArray function. Therefore, if the allocation is done in a loop, the mxDestroyArray should also be called in the loop.
Furthermore, you will have to use the assignment operator "=" to assign values to an mxArray under explicit memory management otherwise you create a memory leak.
With the automated memory management , you have to make sure that:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Software Development Tools finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!