Pass Large Structures as Input Parameters

If you generate a MEX function for a MATLAB® function that takes a large structure as an input parameter, for example, a structure containing fields that are matrices, the MEX function might fail to load. This load failure occurs because, when you generate a MEX function from a MATLAB function that has input parameters, the code generator allocates memory for these input parameters on the stack. To avoid this issue, pass the structure by reference to the MATLAB function. For example, if the original function signature is:

y = foo(a, S)

where S is the structure input, rewrite the function to:

[y, S] = foo(a, S)