setdatatype — Declare the pointee type and extent of an opaque native pointer.
setdatatype(pointer, type, dimensions...) records a typed view of an opaque pointer returned by a native library. It does not allocate or copy the pointee. It applies only to an opaque borrowed pointer, not caller-owned libpointer storage, and requires at least one checked dimension.
Syntax
setdatatype(pointer, type, dimensions...)Inputs
pointer- Type
Any- Required
- Yes
- Default
- —
- Description
- Opaque borrowed native pointer handle.
type- Type
Any- Required
- Yes
- Default
- —
- Description
- Scalar text, number, or logical normalized C pointer type.
dimensions- Type
Any- Required
- Variadic
- Default
- —
- Description
- One or more positive, checked scalar integer values in exact integer or integral-double storage.
Errors
RunMat:Foreign:UnsupportedOnWasm- When
- The current host cannot load a native shared library.
- Message
Native shared libraries are unavailable on this host.
RunMat:Foreign:InvalidCall- When
- Arguments do not satisfy the normalized shared-library contract.
- Message
Invalid shared-library operation.
RunMat:Foreign:HostUnavailable- When
- A native shared-library operation is invoked without an active runtime context.
- Message
Native shared-library operation has no active runtime context.
Borrowed memory
The foreign handle retains its original borrowed ownership, origin affinity, and session lifetime. Dimensions are validated with checked multiplication before the view is published; assigning a type does not authorize an unsafe copy from an unknown address.
The compatibility reference specifies double-valued dimensions. This RunMat implementation also accepts exact integer-class scalar dimensions; that acceptance should not be assumed portable to MATLAB.
Example
Type an opaque pointer returned from C
loadlibrary('fixture', 'fixture.h', 'Alias', 'fixture');
p = calllib('fixture', 'fixture_borrowed_value', int32(1));
setdatatype(p, 'int32Ptr', 1);
assert(p.Value == int32(17));
unloadlibrary('fixture');Using setdatatype with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how setdatatype changes the result.
Run a small setdatatype example, explain the result, then change one input and compare the output.
Related Interop functions
Native
calllib · clibgen.buildInterface · libfunctions · libisloaded · libpointer · libstruct · loadlibrary · unloadlibrary
Java
isjava · javaaddpath · javaArray · javaclasspath · javaMethod · javaMethodEDT · javaObject · javaObjectEDT · javarmpath · jenv · usejava
Source you can read
Every RunMat function's source is public. Read exactly how setdatatype is executed, line by line, in Rust.
- View the source for setdatatype in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.