I am trying to create a matrix in a MEX function. The following works:
我想在MEX函数中创建一个矩阵。以下作品:
uint64_t N;
N = 2147483647; // N = 2*2^30 -1
plhs[0] = mxCreateNumericMatrix(N,1,mxUINT8_CLASS,mxREAL);
However, I am unable to create an array that is this size:
但是,我无法创建这个大小的数组:
uint64_t N;
N = 2147483648; // N = 2*2^30
plhs[0] = mxCreateNumericMatrix(N,1,mxUINT8_CLASS,mxREAL);
The preceding code throws the error:
上面的代码抛出错误:
maximum variable size allowed by the function exceeded
Which is confusing since my system (64-bit Linux running 64-bit Matlab 2010b) tells me the maximum array size is, in fact, very large.
这是令人困惑的,因为我的系统(运行64位Matlab 2010b的64位Linux)告诉我,最大阵列大小实际上非常大。
[~,M] = computer
M =
281474976710655 % 2^48 -1 for those of you keeping track
Furthermore, from the command line, I am able to create very large arrays, and have been quite happily for some time, with calls like the following:
此外,从命令行,我可以创建非常大的数组,并且已经很开心了一段时间,调用如下:
a = zeros(16*2^30,1,'uint8');
disp(uint64(numel(a)))
17179869184
My question is, why am I not able to create arrays in my mex function that I am clearly able to create from the command line, or from other *.m functions?
我的问题是,为什么我无法在我的mex函数中创建我能够从命令行或其他* .m函数创建的数组?
Thank you.
P.S. - I have also asked this question in the Mathworks forum. I figured I'd cast as large a net as possible. If it is answered there first, I'll post it here.
附: - 我也在Mathworks论坛中提出了这个问题。我想我会尽可能地投出大网。如果先在那里回答,我会在这里发布。
1 个解决方案
#1
2
The answer lies in the compiler options. By default, Matlab limits the size to 2^31-1. To increase the size, the following option must be included in your mex compile command.
答案在于编译器选项。默认情况下,Matlab将大小限制为2 ^ 31-1。要增加大小,必须在mex compile命令中包含以下选项。
mex -largeArrayDims myFunction.c
#1
2
The answer lies in the compiler options. By default, Matlab limits the size to 2^31-1. To increase the size, the following option must be included in your mex compile command.
答案在于编译器选项。默认情况下,Matlab将大小限制为2 ^ 31-1。要增加大小,必须在mex compile命令中包含以下选项。
mex -largeArrayDims myFunction.c