assertion error for persistent memory object
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Kaustubha Govind
on 14 Apr 2011
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 Comments
Kaustubha Govind
on 14 Apr 2011
+1 for James' comment that the assertion is caused by recent changes to the API - .\src\mem\alignment.cpp does indeed belong inside MATLAB.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!