API for Generated Reusable Code
When you generate reusable code, MATLAB® Coder™ supports dynamic allocation of:
Function variables that are too large for the stack
Persistent variables
Global variables
It generates a header file, primary_function_name
_types.h
,
that you must include when using the generated code. This header file
contains the following structures:
primary_function_name
StackData
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
primary_function_name
StackData
structure also contains a pointer to theprimary_function_name
PersistentData
structure. If you include this pointer, you only have to pass one parameter to each calling function.primary_function_name
PersistentData
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.