奇怪的 MEX 文件行为
一些奇怪的事情正在发生。我使用 MATLAB R2011 创建了一个 MEX 文件,并使用 Visual Studio 2010 编译了它。
我能够在工作区中正确使用 MEX 文件。 然后,我在 MATLAB m 文件中使用 MEX 文件(多次调用 MEX 文件)。当我尝试运行它时,MATLAB 崩溃并要求我关闭。
尝试分析错误,我放置了断点,但是当我在 m 文件中放置断点时,一切都是正确的。实际上,我运行所有m文件所做的就是在函数末尾放置一个断点并运行正常,我也可以毫无错误地完成所有m文件。
但是当我尝试在没有断点的情况下运行它时,MATLAB 崩溃了......
起初我以为它可能是内存,但为什么它在断点下可以正常工作呢?
如果您能给我解决这个问题的线索,我将不胜感激。
预先感
谢杰西卡
Something weird is happening. I created a MEX-file with MATLAB R2011, and I compiled it with Visual Studio 2010.
I'm able to use the MEX-file in the workspace correctly.
Then, I'm using the MEX-file inside a MATLAB m-file (calls the MEX-file several times). When I try to run it, MATLAB crashes and ask me close.
Trying to analyze the error, I put breakpoints, but when I put breakpoints in the m-file, everything is correct. Actually what I do to run all the m-file is put a breakpoint at the end of the function and runs ok, I also can finish the all m-file without errors.
But when I try to run it without the breakpoints, MATLAB crashes...
At first I thought that it could be the memory, but why it works correctly with breakpoints?
I would appreciate if you could give me a clue to solve this.
Thanks in advance
Jessica
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说听起来也像是内存问题。正如 Laurent 提到的,一些代码会有所帮助。
如果您可以重现崩溃,我建议调试 c 代码本身。确保运行 mex 文件的调试版本,在代码中设置断点,从 Visual Studio (ALt+Ctrl+p) 附加到 Matlab 进程,并从 Matlab 调用 mex 文件。
Sound like memory issue to me as well. Some code would help, as mentioned by Laurent'.
If you can reproduce the crash, I suggest debugging the c code itself. Make sure you run the debug version of the mex file, set a breakpoint in your code, attach to Matlab process from Visual Studio (ALt+Ctrl+p), and call the mex file from Matlab.
我也认为这是一个内存问题。
也许,当您通过调试器启动 mex 文件时,内存处理方式不完全相同,或者问题发生在函数返回后。
您应该尝试使用 启动 matlab这个环境以方便调试。
请注意,内存损坏可能会导致 Matlab 在 Mex 函数出现故障后崩溃。
这意味着您可能正在调试错误的函数。
如需进一步帮助,我需要查看您的代码;)
I also think that it is a memory issue.
Maybe, when you launch your mex file through the debugger, the memory is not handled exactly the same or the issue takes place just after your function returns.
You should try to launch matlab with this environment to facilitate debugging.
Please note that memory corruption can make Matlab crash after the faulty Mex function.
This means that you're perhaps debugging the wrong function.
For further assistance, I would need to see your code ;)