assertion error for persistent memory object

1 次查看(过去 30 天)
I have this code in a mex file to interface with a dll.
plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL);
Status = Reset_Status( In);
mxSetPr(plhs[0], Status);
mxSetM(plhs[0], 10);
mxSetN(plhs[0], 1);
Reset_Status returns a global memory pointer which I want to read out multiple times. On windowsXP 32bit this does not cause problems. On Windows7 32 bit I get an assertion falure;
Assertion failed: Forced Assertion at line 314 of file ".\src\mem\alignment.cpp".
ALIGNMENT ERROR: vector_check: pointer not allocated with vector_*alloc
PID: 2256
NATIVE ALIGNMENT: 8 (0x8)
REQ ALIGNMENT: 16 (0x10)
ALIGNED POINTER: 19BD2168
REQ SIZE: 0 (0)
HEADER ADDRESS: 00000000
HEADER SIZE: 8 (0x8)
HEADER DATA: INACCESSIBLE
How should I resolve this?

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-4-14
Since all memory held by variables passed in and out of MEX-functions is managed by MATLAB, it is not advisable to use mxSetPr to set (externally owned) data on a variable being returned to MATLAB. There is a danger of that memory being de-allocated by MATLAB.
Instead, I would recommend copying that data from your global buffer into plhs (which must be allocated using a call to mxCreateDoubleMatrix).
As for why this issue is not caught on XP - I wonder if the C runtime libraries are simply more robust on Windows 7?
  5 个评论
Kaustubha Govind
Kaustubha Govind 2011-4-14
+1 for James' comment that the assertion is caused by recent changes to the API - .\src\mem\alignment.cpp does indeed belong inside MATLAB.
Chris van der Togt
Chris van der Togt 2011-4-15
Thank you for your answers, that clears things up. It's a shame though, this global array was filled by a callback routine triggered by an IO card. So all I had to do was read out the values from time to time. But copying them off is not so bad.
But I'm surprised that in the matlab help files this method of setting pointers is shown as good practice.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by