Mex file crash on Windows 64bit environment
9 views (last 30 days)
Show older comments
Hi,
I am developing a piece of code inside a mex function. I output interface is something like this
Output = mxCreateNumericMatrix(SIZE, 1,mxLOGICAL_CLASS,mxREAL);
dec = (bool*)mxGetData(Output);
After this, i dynamically allocate memory to an other entity
if (( Table =
(uint16_t*)mxMalloc(sizeof(uint16_t) * SIZE)) == NULL)
{
}
Now, When i print the address's of Table and also dec, i find that they overlap.
Any idea on what could be happening? Is this an issue with windows 64 bit environment?.
At the end, while freeing the Table pointer there is a crash.
but the same code works fine on 32bit machine.
Thanks, Kishore.
0 Comments
Accepted Answer
Walter Roberson
on 15 Dec 2011
Which compiler are you using?
On some compilers, bool can be 4 bytes rather than 1 byte. See for example http://msdn.microsoft.com/en-us/library/tf4dy80a.aspx
I also find record of a compiler for which bool was 8 bytes.
0 Comments
More Answers (6)
Jan
on 15 Dec 2011
Please post more code. The cause of the crash is somewhere else. Of course there is no general problem with 64 bit systems, which would create overlapping memory blocks.
Are you sure that mxLogical has the same size as bool? I'd stay at mxLogical for dec.
How do you "print the address"? Do you use "%i" or "%li" as format?
0 Comments
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!