Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: mxCreateNumericArray maximal array size
Replies: 8   Last Post: Jun 6, 2012 10:16 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Steven Lord Posts: 17,544 Registered: 12/7/04
Re: mxCreateNumericArray maximal array size
Posted: May 14, 2012 4:25 PM
 Plain Text Reply

"shlomi golubev" <e271p314@yahoo.com> wrote in message
news:jorop9\$p5g\$1@newscl01ah.mathworks.com...
> I have this mex code
> ...
> dims[0]=2*(2*n-1); dims[1]=2*(2*n-1); dims[2]=2*(2*n-1);
> plhs[0]=mxCreateNumericArray(3,dims,mxSINGLE_CLASS,complexFlag);
> ...
> for n <= 323 it works fine, but for n >= 324 matlab crashes with an ugly
> core dump.
>
> I checked what is so special about these numbers and it appears that this
> is exactly the point where (2*(2*n-1))^3 becomes bigger than 2^31.
>
> so I run another test like this
>
> ...
> dims[0]=2*(2*n-1); dims[1]=2*(2*n-1);
> plhs[0]=mxCreateNumericArray(2,dims,mxSINGLE_CLASS,complexFlag);
> ...
>
> again same result only this time for n <= 23170 it works fine, but for n

> >= 23171 matlab crashes with an ugly core dump
>
> so the problem is obvious, any chances to fix it soon or to provide some
> work around?

Do you check to make sure that plhs[0] is not NULL before trying to use it?
See the Returns section of:

http://www.mathworks.com/help/techdoc/apiref/mxcreatenumericarray.html

My guess is that you're on a 32-bit OS, in which case you should check the
second output of the COMPUTER function in MATLAB. It may look familiar.

The "workaround" is to test the output of mxCreateNumericArray before using
it and do something appropriate if it's NULL. Another possibility is to
consider a 64-bit OS if you want to create very large arrays.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Date Subject Author
5/14/12 shlomi golubev
5/14/12 Steven Lord
5/14/12 James Tursa
5/15/12 shlomi golubev
5/15/12 James Tursa
5/21/12 shlomi golubev
5/22/12 Steven Lord
6/6/12 shlomi golubev
6/6/12 Steven Lord

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.