When you generate reusable code, MATLAB® Coder™ supports dynamic allocation of:
Function variables that are too large for the stack
It generates a header file,
that you must include when using the generated code. This header file
contains the following structures:
This structure contains the user-allocated memory. You must pass a pointer to this structure as the first parameter to all functions that use it:
Directly, because the function uses a field in the structure.
Indirectly, because the function passes the structure to a called function.
If the algorithm uses persistent or global data, the
also contains a pointer to the
If you include this pointer, you only have to pass one parameter to
each calling function.
If your algorithm uses persistent or global variables, MATLAB Coder provides a separate structure for them. The memory allocation structure contains a pointer to this structure. Because you have a separate structure for persistent and global variables, you can allocate memory for these variables once and share them with all threads. However, if there is no communication between threads, you can allocate memory for these variables per thread.
For more information on using these global structures, see Multithreaded Examples.