deepCopy
First introduced in version: 3.00.3
Syntax
deepCopy(obj)
Details
Returns a deep copy of obj. A deep copy copies all mutable elements, resulting in a fully independent replica of the original object.
The difference between copy (shallow copy) and
deepCopy (deep copy) is most evident when dealing with
nested structures such as tuples or dictionaries of type ANY:
copyonly duplicates the top-level structure, while sub-objects retain shared references (i.e., the sub-object addresses remain unchanged).deepCopyrecursively copies all sub-objects, ensuring fully independent references.
For special table objects such as streamTable, keyedStreamTable,
latestKeyedStreamTable, haStreamTable, changelogStreamTable, mvccTable,
haMvccTable, or IPC in-memory tables, deepCopy returns a regular
in-memory table. The copy preserves the data and schema, but not the original table
type or streaming, high-availability, MVCC, or IPC-specific behavior.
schema(result).tableType returns "table".
Parameters
obj can be of any data type.
Returns
Returns a deep copy of obj.
For the special table objects described above, returns a regular in-memory table.
Examples
Example 1. Copy a vector
x = 1 2 3
a = x.copy()
b = x.deepCopy();
print constantDesc(x[0]).address // 000000000dd3d640
print constantDesc(a[0]).address // 000000000cb5a4c0
print constantDesc(b[0]).address // 000000000de92c20
Example 2. Copy a tuple
x = ([[1, 2], [3, 4]], "a")
a = x.copy()
b = x.deepCopy();
print constantDesc(x[0]).address // 000000000c7ce880
print constantDesc(a[0]).address // 000000000c7ce880
print constantDesc(b[0]).address // 000000000c89be00
Example 3. Copy an ANY dictionary
y = dict(`A`B`C, (1 2, 3 4, 5 6))
c = y.copy()
d = y.deepCopy();
print constantDesc(y[`A]).address // 000000000c88c450
print constantDesc(c[`A]).address // 000000000c88c450
print constantDesc(d[`A]).address // 000000000c7cde00
