Main Content

Compare MWArray and Native .NET API for Remotable Assemblies

The two data conversion APIs that marshal and format data across the managed (.NET) and unmanaged (MATLAB®) code boundary are MWArray and the native .NET API. Each API has advantages, limitations, and particular applications for which it is best suited.

The MWArray API, which consists of the MWArray class and several derived types that map to MATLAB data types, is the standard API that has been used since the introduction of MATLAB Compiler SDK™. It provides full marshaling and formatting services for all basic MATLAB data types including sparse arrays, structures, and cell arrays. This API requires MATLAB Runtime to be installed on the target machine, as it makes use of several primitive MATLAB functions. For information about using this API, see Access Remotable .NET Assembly Using MWArray API.

The Native API was designed especially, though not exclusively, to support .NET remoting. It allows you to pass arguments and return values using standard .NET types when calling the deployed MATLAB function. Here, data marshaling is still used, but it is not explicit in the client code. This feature is especially useful for clients that access a remotable component using the native interface API, as it does not require the client machine to have MATLAB Runtime installed. In addition, as only native .NET types are used in this API, there is no need to learn the semantics of a new set of data conversion classes. This API does not directly support .NET analogs for the MATLAB structure and cell array types. For information about using this API, see Access Remotable .NET Assembly Using Native .NET API: Magic Square.

Features of the MWArray API Compared With the Native .NET API

 MWArray APINative .NET API
Marshaling/formatting for all basic MATLAB typesX 
Pass arguments and return values using standard .NET types X
Access to remotable component from client without installed MATLAB X
Access to remotable component from client without installed MATLAB Runtime (see Access Remotable .NET Assembly Using Native .NET API: Cell and Struct). X

Using Native .NET Structure and Cell Arrays

The MATLAB Compiler SDK native .NET API accepts standard .NET data types for inputs and outputs to MATLAB function calls.

These standard .NET data types are wrapped by the Object class—the base class for all .NET data types. This object representation is sufficient as long as the MATLAB functions have numeric, logical, or string inputs or outputs. It does not work well for MATLAB data types like structure (struct) and cell arrays, since the native representation of these array types results in a multi-dimensional Object array that is difficult to comprehend or process. Instead, MATLAB Compiler SDK provides a special class hierarchy for struct and cell array representation designed to easily interface with the native .NET API. See Access Remotable .NET Assembly Using Native .NET API: Cell and Struct for details.

Related Topics