MATLAB: Mex: out of memory mxCreateNumericArray

arraycdimdimensionlarge arrayMATLABmemorymexmxcreatenumericarrayout of memory

Hello,
i m getting an error "out of memory" when i m declaring an large array. but when i m declaring an small array it works. Unfortunately i m beginner in mex. Can someone tell pls how i can solve this problem? Many many thanks!
// works
int dim[3] = {400,3,1000};
plhs[0] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
// doesnt work
int dim[3] = {4000,3,10000};
plhs[0] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);

Best Answer

Hi,
that works fine for me. I assume you use a 32bit MATLAB? The variable you create needs 960mb of memory in one piece which is most likely not available for you.
You can use the memory command (Windows only!) to see what the biggest matrix is you can allocate.
Small advice: Don't use an int for the dimensions. Use mwSize. This is a bittedness independent type.