0

What is the difference between copy and deep_copy methods in e language?

When do i have to use deep_copy(), and when using copy() is good enough?

Thanks!

Raz
  • 175
  • 5

4 Answers4

1

copy copies the scalar fields,and keep references to the sub structs. While deep copy recursively copies all sub structs.

Zvika
  • 1,542
  • 2
  • 17
  • 21
0

To copy scalars use copy. - will refer to sub structs. To copy sub-structs use deep copy.

Noam Arzy
  • 11
  • 2
0

Copy() copies only the scalar values, struct pointers and references the same list. Deep_copy() will create new struct instances recursively and assign new list and create the list elements. If the list elements are structs, then these will also be new instances

igsh
  • 1
  • 1
0

The difference is that copy() is shallow means it copy values of scalars and pointers to lists or structures. Deep_copy() is stronger copy with attributes for control the copy() method like reference or creation of new list/struct. When you need shallow copy with no concern to deeper hierarchy use copy(). When we need to give attention to deeper hierarchy use deep_copy().

Assaf
  • 79
  • 4