Questions tagged [deep-copy]

A deep copy of an object is a separate, fully independent duplicate of that object, such that any references / pointers it holds to other objects refer to deep copies of those to which the original's refer. Use this tag for questions regarding implementing or using deep copying methods.

Deep copying is a process by which an object is fully duplicated to create a copy that is wholly independent of the original. This differs from shallow copying with respect to the treatment of references / pointers to other objects: deep copying makes a deep copy of each referenced object, too, whereas shallow copying copies only the references. Deep copying is "deep" in the sense that it traverses the object's reference graph all the way to the bottom.

Related tags

Links

1483 questions
-1
votes
1 answer

Why is the list.copy() method shallow?

In the official Python documentation said that list.copy() returns a shallow copy of the list. But according to the following code it is deep copy since the change of one list does not lead to the change in another. >>> num1 = [1,2,3,4,5] >>> num2 =…
-1
votes
2 answers

Overloading a function to use an rvalue reference instead of an lvalue reference

I am creating a doubly linked list template and I have to write 2 constructors where we pass in a linked list, and then construct a new list that has the same number of nodes as well as the same numbers in those nodes. The memory locations of the…
user12160874
-1
votes
2 answers

Javascript spread notation and deep copy of array of object explanation

Consider the following code, let a =[{b:{c:100}}] let c = [...a] c[0].b = {l:200} console.log( a ) Output is: Array [Object { b: Object { l: 200 } }] Given c[0] is a new object and c[0].b is a reference. Changing the reference of b should…
muhammad800804
  • 105
  • 1
  • 8
-1
votes
2 answers

How to properly allocate enough memory (malloc) when creating a new struct in C?

Given the struct below, I am creating a function that takes in a person_in_queue and a position_num and allocating a new queue_t struct that is added to the end of a list of queue_t structs as specified by the first argument. typedef struct queue { …
Kakary
  • 1
  • 1
-1
votes
1 answer

Python cant pickle getset_descriptor

I was trying something with types.MappingProxyType: class MyClass: l = [1, 2] proxy = MyClass.__dict__ Then I wanted to extract dictionary from this Proxy: d = proxy.copy() print(type(d)) # Then I wanted to append something to…
Ekrem Dinçel
  • 1,053
  • 6
  • 17
-1
votes
1 answer

How do you avoid 3d arrays from being linked in Python?

I've been trying to copy a 3D array but it seems like no matter what I do; amending the copy, amends the original as well. I've tried multiple veriants of the top advice given on this question. Can anyone explain to me why this code is amending the…
-1
votes
1 answer

How to make a deepcopy of a dataframe with dataframes within it? (python)

I want a copy of a dataframe which contains a dataframe. When I change something in the nested dataframe, it shouldn't change in the original dataframe. I have a dataframe like this: 0 1 2 0 1 2…
Robb
  • 1
  • 4
-1
votes
1 answer

C# Each Classes Write and Receive by One SerialPort or How to DeepCopy SerialPort?

I have three class, main, serial, meter. main is create new instance of meter and add list for management, when user clicked button. // main.cs MeterPanel meter = new MeterPanel(meterid); list_Meters.Add(meter); And each meter has an instance of a…
NWOWN
  • 399
  • 1
  • 4
  • 17
-1
votes
2 answers

in c# code why below copy didn't work as reference copy?

Below c# code I run in Visual Studio 2019 Mac, I am a little surprise for the result: using System; namespace Test { public struct Point { public int x; private int y; public Point(int x, int y) { …
Penny
  • 606
  • 1
  • 7
  • 15
-1
votes
2 answers

Clone array of object removes class type

I have to deep clone an array of objects filterList: Filter[] = [ new ChipsFilter('Rating', 'rating', [ { name: '5 ★', key: '5', value: true }, { name: '4 ★', …
Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93
-1
votes
1 answer

How to deep copy a 2d String array?

public static String[][] deepCopy(String[][]toclone){ String[][]clone = new String[4][4]; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { if(toclone[i][j] != null) { String s = new…
Heiko
  • 55
  • 5
-1
votes
1 answer

Object changes the original value. Are there other methods than deepcopy?

I was reading this post and now am trying to create a class to modify a dictionary and store the modified dictionary in a new variable, without any effect on the original dictionary. Here is the code: dict_1 = {'a':[0,1,2]} print('dict_1 before…
Muser
  • 593
  • 1
  • 9
  • 23
-1
votes
2 answers

Numpy operation *= is repeating, despite it's in a function

I would like to understand why I don't delete the array in spite of function call in case of Numpy? In the case of the function call mul2 exactly what should happen happens. But if I try exactly the same with mul, I have a kind of reference to the…
Airfox
  • 51
  • 1
  • 5
-1
votes
1 answer

A deep copy of list of objects instantiates new objects?

First I have written a class I need for some purposes. I have several objects of this class And I have put them in a list. It could be something like: obj0=created_class(0) obj1=created_class(1) List_of_obj=[obj0,obj1] Now I need a deep copy of the…
user2988577
  • 3,997
  • 7
  • 21
  • 21
-1
votes
1 answer

c# Deep Copy reflection GetMembers

I am trying to deep copy a complex object public class Team { public string id { get; set; } public Driver driver{ get; set;} public Driver codriver{ get; set;} } public class Driver { public Team parentTeam{ get; set;} public…
Kavya Shetty
  • 185
  • 2
  • 14