loadlibrary
is MATLAB's implementation of FFI services, a mechanism of calling functions in external shared libraries. It involves converting between C-types and their equivalent MATLAB data types to pass data around.
MEX-files are also a kind of dynamically linked libraries (with .mex*
extension), that can be run directly in MATLAB as a regular function without any special syntax.
The difference is that it has a specific gateway routine called mexFunction
, which receives both input and output as mxArray
type. mxArray
is an opaque type defined in mex.h
header file, which is the fundamental type underlying all MATLAB data. You usually manipulate this data using functions in the MEX library API.