Filter löschen
Filter löschen

Beginner: Mex array size too large?

3 Ansichten (letzte 30 Tage)
mick strife
mick strife am 19 Apr. 2013
Hello my friends,
i m a beginner with mex, so may be someone could help me please. i want to define a large array in my mex-code but at some point matlab crashes. Does somebody have an idea why or have a proposal for a solution? Many thanks! :)
Heres the code:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
float myArray[106*3*7555]; // doesnt work but works with a smaller definition

Akzeptierte Antwort

James Tursa
James Tursa am 19 Apr. 2013
Your myArray is a local variable, meaning that the memory for it is obtained from the stack. The stack for your program is typically limited in size to a much smaller amount than the heap. To get your variable allocated from the heap instead of the stack you can allocate it with one of the memory allocation functions, e.g.:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
float *myArray;
myArray = mxMalloc(106*3*7555*sizeof(*myArray));
// insert code to use myArray
mxFree(myArray);
}
  1 Kommentar
mick strife
mick strife am 20 Apr. 2013
Thank you so much for your effort. Even the background notes were helpful. have a nice weekend! :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by