StackOverflow exception when using Matlab Coder ?

2 Ansichten (letzte 30 Tage)
Baptiste PERRIN
Baptiste PERRIN am 22 Mär. 2016
Beantwortet: Baptiste PERRIN am 31 Mär. 2016
Hello,
I'm a new user of Matlab Coder and I try to translate my Matlab code in C. My matlab code uses the Image toolbox, and in the entry-point function, I have a buffer of 1920*1080 pixels. So, when I generate the C code, the function has "const unsigned int buffer[2073600]" as an entry-point and I think that is the cause of the exception. So, how can I said to matlab coder to not write in the stack and take a pointer in entry-point ? Thank you for this community,
Baptiste

Akzeptierte Antwort

Baptiste PERRIN
Baptiste PERRIN am 31 Mär. 2016
Hi Vidya, Thank you for your answer. I actually solved my problem: in a function we cannot have a temporary variable with a memory allocation bigger than 4Kb (I think), and I had 1920*1080 images. So I found the option of dynamic allocation in the settings of Matlab Coder and now it works.
Thank you,
Baptiste

Weitere Antworten (1)

Vidya Viswanathan
Vidya Viswanathan am 31 Mär. 2016
Hi Baptiste,
As per my understanding, arrays are always passed by reference in C programming (by default). For example, consider the following code that is generated from a MATLAB function that accepts a matrix of size 1920 x 1080 as input and returns a matrix of the same size:
void MultBy2(const double u[2073600], double y[2073600])
{
int i0;
for (i0 = 0; i0 < 2073600; i0++) {
y[i0] = u[i0] * 2.0;
}
}
Although the argument in the function is of the form "const double u[2073600]" rather than "const double* u[2073600]", the function that calls "MultBy2" (after creating an array of dimensions 1920 x 1080 and passing the name of the array) would still pass the array by reference (because the name of the array is a pointer to the first location of the array). Therefore, I feel that there would be no variable created in the stack.
I am not sure if this answers your question. I apologise if I have misunderstood your query. It would be very helpful if you could post the exact error message that you are receiving.
Regards,
Vidya

Community Treasure Hunt

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

Start Hunting!

Translated by