Why does my class destructor not execute after an error occurs in a C++ MEX-file in MATLAB?
6 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2009 年 6 月 27 日
コメント済み: Prannay Jain
2017 年 2 月 23 日
I have created a C++ MEX-function. In the MEX-function, I create instances of a class. This class has a destructor which performs some cleanup. I expect the destructor to be called whenever the class instance goes out of scope. However, when an error occurs in the MEX-function, the destructor does not seem to be called.
採用された回答
MathWorks Support Team
2009 年 6 月 27 日
This is a limitation of several C++ compilers which are supported for creating MEX-functions in MATLAB. The following compilers are known to have this limitation:
On 32-bit Windows:
Visual Studio C++ 6.0
OpenWatcom 1.3 and 1.7
On 64-bit Solaris:
GCC
The destructors are not called because these compilers have exception handling mechanisms which are not compatible with the compilers used to build MATLAB. The symptom of the problem is that class destructors do not get called if an error occurs during a call to a MATLAB API function. They do still get called on normal exit.
Note that all other more recently added compilers (in particular, Microsoft Visual C++ 2008) handle destructors in ways compatible with MATLAB build compilers.
1 件のコメント
Prannay Jain
2017 年 2 月 23 日
As mentioned above, this is a limitation of C++ compilers, not MATLAB. Most of the modern compilers handle destructors in ways compatible with MATLAB build compilers.
Calling mexErrMsgTxt does not clear the MEX-file from memory. So, mexErrMsgTxt does not invoke the function registered through mexAtExit.
mexAtExit is called when MEX function clears or MATLAB terminates.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!