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
-2
votes
5 answers

A 'deep copy' constructor in C++

I want to build a copy constructor Pair(const Pair& other). This takes as its argument a read-only reference to another Pair. It should set up the newly constructed Pair as a "deep copy". But I have no idea on how to set up the integers at these new…
robinzx117
  • 11
  • 1
  • 2
-2
votes
1 answer

How I can write a function returns a deep copy of the three dimensional array at the index in Java?

In this assigment, you have to implement a simple tour planing system. The data for the available tours, each with multiple way points, is statically given. A single waypoint consists of a x-value and a y-value. I have to write 2 function: int…
-2
votes
1 answer

Deep copy of an ArrayList

I'd like to copy the ArrayList zf into the ArrayList copyzf. The copy has to be a deep one. I already tried: public class ZFW { Integer zfw; public ZFW copy() { ZFW m= new ZFW(); m.zfw=this.zfw.copy(); return m; } } and in the…
-2
votes
4 answers

How is the assignment operator creating a deep copy?

Below is the code a =2 b = a b = 3 print (b,a) 3 2 I expect the value of a also to change to 3 , if b is only pointing to a's memory space and does not have it's own memory. I am sure there is a very simple explanation which i am missing.
-2
votes
1 answer

Copy constructor of Array List

I just read about deep copy of ArrayList, that people think new ArrayList<>(originalList); will create a shallow copy. And I wrote a small demo ArrayList originalNameList = new ArrayList<>(Arrays.asList("Anna", "Betty", "Chris")); …
Huy Hóm Hỉnh
  • 597
  • 7
  • 18
-2
votes
1 answer

passing of structure with pointer member in function is shallow copy or deep copy In C

In C++, there is overloaded copy constructor and assignment overloading for a deep copy. Since default available is a shallow copy. In C, the structure which has pointer member, if passed to a function or assigned to already created new struct…
Laxmi Kadariya
  • 1,103
  • 1
  • 14
  • 34
-2
votes
1 answer

C# Deep Copy from inside the object

I have an object with a number of private properties. It has an empty constructor, and a constructor that accepts an instantiated version of itself. I need to assign this new instance to a deep copy of the old instance. Can this be…
-2
votes
1 answer

Two OrdereDict's contained in class share object id regardless of copy method

I have a class in python that is used to generate parameter files for a piece of software. This software is used in an iterative process and requires a new set of parameter files for each iteration. As such the class PropGen is called upon to create…
Grr
  • 15,553
  • 7
  • 65
  • 85
-2
votes
1 answer

Creating copies of my objects

I am a beginner, and I wonder about the following. Let's say I have a class foo and created an object foo first and put some data into it: foo first = new foo(); first.data="mydata"; I then want to create another object foo second and make it have…
Kagaratsch
  • 963
  • 8
  • 18
-2
votes
1 answer

Does listIterator.next() return deep copy or shallow copy?

I have following piece of code: ListIterator iterator = resultSet.listIterator(); while (iterator.hasNext()) { Object[] data = (Object[]) iterator.next(); } I just want to know whether iterator.next() method returns deep copy of next item in…
maximus335
  • 674
  • 1
  • 5
  • 19
-2
votes
1 answer

Strange behavior of Python's deepcopy with update

So I try to make a deepcopy of dict and update it with some additional data (I don't want to change my original dict): >>> a = {1:1} >>> print(a) {1: 1} >>> b = copy.deepcopy(a).update({2:2}) >>> print(b) None But when I do it in another way, it…
valignatev
  • 6,020
  • 8
  • 37
  • 61
-2
votes
2 answers

Deep copying (Linked List)

This is just a test program (my original program gets data from a file so i omitted that since it might complicate people from understanding my problem) Anyways, I tried deep copying my object data but I'm get a "null" when i print the copy method?…
Mathy
  • 111
  • 2
  • 6
-2
votes
2 answers

copy constructor - am I setting my std::strings correctly

My question is a basic one. Since std::strings are arrays am I handling them correctly in my copy constructor? class json{ private: std::string _objectContents; std::string _regComments; bool _isJson; int…
user249806
  • 299
  • 1
  • 3
  • 14
-2
votes
1 answer

`Arrays,copyOf` didn't do a deep copy of objects as it is supposed to

I have classBook which can have many Authors. I pass few objects of class Author to the constructor of class Book then copy these objects by Arrays.copyOF but then if I change any Author data outside the object it will change everywhere so it means…
Yoda
  • 17,363
  • 67
  • 204
  • 344
-3
votes
1 answer

C++ parent object loses the internal data of the child object, something wrong related to copy constructor or passing by reference?

My question is explained in the example below. It is weird that the parent object loses the internal data of its child object, if the parent object is instantiated before the child object populates its internal data. The code has a TicketService,…
1 2 3
98
99