Strategies for Passing Structures
MATLAB automatically converts a structure to the library definition for that
structure type. For most cases, such as working with small structures, this works
fine.
However, when working with repeated calls that pass large structures, convert the
structure manually before making any calls to external functions. You save
processing time by converting the structure data only once at the start rather than
at each function call. You can also save memory if the fields of the converted
structure take up less space than the original MATLAB structure.
To convert manually, call the libstruct function to create a
libstruct object. Although it is an object, it behaves
like a MATLAB structure. The fields of the object are derived from an externally
specified structure type.