Clone Objects And References
Basic Concepts
OSL provides two ways to assign arrays and objects:
=
creates a deep clone (complete copy)@=
creates a reference (points to the same data)
Deep Cloning
When using =
, OSL creates a complete copy of the object or array:
References
Using @=
creates a reference to the original data:
When to Use Each
Use
=
when you need a separate copy that can be modified independentlyUse
@=
when you want multiple variables to point to the same dataUse
=
to prevent accidental modifications to the originalUse
@=
to save memory when working with large data structures
Important Notes
=
creates a complete copy of all nested structures@=
maintains a single copy with multiple referencesModifying a reference affects all variables pointing to the same data
References are useful for passing large objects efficiently
Deep clones are safer but use more memory
Last updated
Was this helpful?