saveobj — Return the MAT-file serialization payload for an object.

saveobj(a) returns the payload that save should write for object a. If the object's class registers a saveobj method, RunMat dispatches to that method. Otherwise RunMat returns a scalar struct containing the object's stored public runtime properties.

Syntax

b = saveobj(a)

Inputs

NameTypeRequiredDefaultDescription
aAnyYesObject to serialize.

Returns

NameTypeDescription
bAnySerialized object representation.

Errors

IdentifierWhenMessage
RunMat:ObjectSerialization:InvalidArgumentThe input is not an object or serialized object envelope.object serialization: invalid argument
RunMat:ObjectSerialization:DispatchA saveobj or loadobj method cannot be resolved or executed.object serialization: method dispatch failed
RunMat:ObjectSerialization:RecursionLimitObject serialization nesting exceeds the supported recursion limit.object serialization: recursion limit exceeded

How saveobj works

  • The public signature is b = saveobj(a).
  • Object and handle-object inputs dispatch to a registered Class.saveobj method when one is available.
  • When no registered overload exists, RunMat serializes the object's stored property map as a scalar struct.
  • Nested objects inside structs or cells are serialized recursively before MAT-file encoding.
  • save automatically applies this object serialization path before writing MAT-file variables.
  • Recursion is bounded and reports RunMat:ObjectSerialization:RecursionLimit for cyclic or excessively nested object graphs.
  • Non-object inputs to direct saveobj raise RunMat:ObjectSerialization:InvalidArgument.

Does RunMat run saveobj on the GPU?

saveobj does not launch provider kernels.

save remains the residency sink for any GPU values that appear inside the serialized payload.

GPU memory and residency

saveobj itself is host-side object metadata work. If a serialized payload contains GPU-resident numeric properties, save gathers those values when it converts the payload to MAT-file arrays.

Examples

Return a default property payload

obj = new_object('Point');
payload = saveobj(obj)

Save an object through MAT-file serialization

obj = new_object('Point');
save('object_state.mat', 'obj')

Using saveobj with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how saveobj changes the result.

Run a small saveobj example, explain the result, then change one input and compare the output.

FAQ

Does save call saveobj automatically?

Yes. Before MAT-file encoding, RunMat walks selected values and applies registered saveobj methods for object and handle-object values.

What is saved when no class-specific method exists?

RunMat writes the current runtime property map in an internal object envelope so load can reconstruct an object with the same class name and stored properties.

Are handle identities preserved?

No. Current support serializes the referenced object's properties. It does not preserve handle identity, listener state, or aliasing relationships across save/load.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how saveobj is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.