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

How to create a deep copy in java

My question is how to make a deep copy in java. Right now this is my code but I don't think this is correct. @Override public ListInterface copy() { ListerInterface temp = new List(); if (isEmpty()) { return null; }…
-1
votes
1 answer

Value copy without using serialization in c#

I have two lists and I am trying to copy the source to the target. In the new iteration, changing the source affects the target. I understand, I am making a reference copy. Is there a way to make deep copy without using any serializer(due to…
-1
votes
1 answer

Will pointers in a object created using deep copy point the objects in the original object

Say i have this class: class Entity { private: std::vector _components; public Entity(std::vector); }; And i do this: Entity* entity= new Entity( { new Drawable(), new Transform() ... } ); Entity* clone = new…
ojoj kolol
  • 79
  • 6
-1
votes
1 answer

Making a deep copy of a struct with arrays in it?

After googling I've learned that it's not possible unless you do it manually. Take this code for example: public struct SEverything { public int[] arrayOfHouseNumbers; public string nameOfOwner; } I only know of a very cumbersome way to…
-1
votes
2 answers

Stack copy constructor

I'm having a lot of difficulty with my stack copy constructor. DSStack extends a Stack abstract class and uses a doubly-linked-list to store data (tokens). It keeps failing (NullPointerException) at the line this.push(oldListNode.getToken()); in the…
-1
votes
1 answer

GO - Is array copy a deep copy or shallow copy?

For the below array, var a[2][3]int a[0][0] = 55 a[0][1] = 56 a[0][2] = 57 a[1][0] = 65 a[1][1] = 66 a[1][2] = 67 on performing array copy, a[0] = a[1] Question: Is the array(a[0]) copy a deep copy or shallow copy? After copy, Does a[0] have…
overexchange
  • 15,768
  • 30
  • 152
  • 347
-1
votes
2 answers

Copying a Private Data member

I'm working on a program which states: Create a Java Stock class to represent information about a stock that is bought and sold....Whenever the stock price is changed, the change in price per share is also updated. Omit the setter for the change in…
-1
votes
1 answer

Why does my deep array copy change it's value outside for loop in Java?

I'm creating a Genetic Algorithm written in Java. The mutation function flips the bits in the array at an assigned probability. The mutation function is not retaining the mutated population of arrays (Individuals). public static void…
-1
votes
1 answer

Copied object changes attributes from the base class pointer it used to copy

Consider the following classes: class Base { public: ... // include virtual destructor and rest of methods virtual void changeField(int val) = 0; virtual Base * clone() const = 0; }; class Derived: public Base { int x; …
CSishard
  • 21
  • 5
-1
votes
1 answer

C++ copying a string array within context of defined class

So I'm trying to write a copy function that copies all the elements of a dynamically allocated string array. In my header file I have it defined as having the following type/return values: #include #include using…
TigerCode
  • 315
  • 3
  • 15
-1
votes
1 answer

Storing a copy of current object

I have a class : `class Myclass { public: MyClass ( void ); AddNumber ( const int num ); CopyCurrentObject ( void ); private: int * array int size; int maxSize; MyClass * objetcts[10]; } How can I create a…
kvway
  • 494
  • 4
  • 16
-1
votes
1 answer

Send struct with double pointer to struct over network

Send struct with double pointer to struct over networkI have to send this huge structure that represents the directory structure over network. It looks like this: typedef struct{ char *name; int count; dir **subdir; }dir; I have to send…
MaxSteel
  • 259
  • 1
  • 6
  • 18
-1
votes
1 answer

java object assignment between three references

I've been studying for coding interviews and I have a question about java object assignments. say I have a Node class and I create three instances. Node a = new Node(1); Node b = new Node(2); Node c = new Node(3); Now let's say I do an assignmet a…
intrepistar_88
  • 544
  • 1
  • 4
  • 11
-1
votes
3 answers

Type 'System.Data.DataRow' in Assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable

I am getting following error while serializing the object into steams. Type 'System.Data.DataRow' in Assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable internal static object…
-1
votes
2 answers

Deep clone by collecting the fields

I have classes which aim to contain many attributes of different types. I would want to automatically deep clone all of them rather than writing an instruction for each of them: class AttributesContainer implements Cloneable { Type1 a1 = new…
Codoscope
  • 892
  • 1
  • 10
  • 18