Main Content

How Type-Safe Interfaces Work

Every MATLAB® Compiler SDK™ .NET assembly exports one or more public methods that accept and return data using MWArray objects.

Adding a type-safe interface to a MATLAB Compiler SDK assembly creates another set of methods (with the same names) that accept and return native .NET types.

The figure Architecture of a Deployed Component with a Type-Safe Interface illustrates the data paths between the .NET host application and the deployed MATLAB function.

Architecture of a Deployed Component with a Type-Safe Interface

The MATLAB function addOne returns its input plus one.

Deploying addOne with a type-safe interface creates two .NET addOne methods:

  • One that accepts and returns .NET double

  • One that accepts and returns MWArray.

You may create multiple type-safe interface methods for a single MATLAB function. Type-safe interface methods follow the standard .NET methods for overloading.

Notice that the type-safe methods co-exist with the MWArray methods. Your .NET application may mix and match calls to either type of method, as appropriate.

You may find MWArray methods more efficient when passing large data values in loops to one or more deployed functions. In such cases, creating an MWArray object allows you to marshal the data only once whereas the type-safe interface marshals inputs on every call.