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
0
votes
1 answer

Deep copy between two 2D Arrays in Processing

For a project i'm working on, I have two grids formed by 2D Arrays, one of which allows the user to draw an image into it, the other displays the last image submited. However my code is making a shallow copy of it instead of a deep one, and I need…
Sparky
  • 1
  • 3
0
votes
1 answer

Lazy copying - how to create a deep copy from shallow copy

I have a class which is using lazy copying - when a copy constructor is called, it creates shallow copy and when one method is called it creates a deep copy and add some more data. I'm stuck in part where I should create a deep copy from that…
0
votes
3 answers

Making a deep copy using a constructor in Java

I am using these instructions for the method: A constructor, public ProgrammingTeam( ProgrammingTeam p ), that takes a ProgrammingTeam p as a parameter and constructs a deep copy of p. Don’t just write meets = p.meets;. To make a deep copy,…
user2272710
  • 1
  • 1
  • 2
0
votes
3 answers

Java clone() method using new keyword and a copy constructor instead of super.clone()

When searching the net for possibilities how to make a deep copy of an object polymorphically, I found a solution that claims to solve many issues with the clone() method, e.g. the impossibility to clone final fields. The solution combines the use…
Posa
  • 320
  • 3
  • 8
0
votes
2 answers

Returning self.__dict__ from a method

I am working with a nice little python module from a third party, and I ran across a bit that has got my brain all twisted, and I'm mostly concerned with data integrity. Quick summary: there is a class method that goes roughly as such: def…
user2097818
  • 1,821
  • 3
  • 16
  • 34
0
votes
2 answers

Deep Copy is not working

in the follwing example am doing deepcopy, every thing works fine but when the obj2 goes out of scope, destructor is calling and it is getting crash inside destructor so please help what is wrong with my code: #include "stdafx.h" #include…
nagaradderKantesh
  • 1,672
  • 4
  • 18
  • 30
0
votes
1 answer

deep copy in python

I was working with Python deep copy trying to create a total copy of original object, but the deep copy didn't seem to create a copy. It still shares the same reference with original object, which is not desired Here's the code. I have a class…
Daniel
  • 1,484
  • 5
  • 24
  • 42
0
votes
1 answer

Mutable deep-copy of a NSMutableDictionary

First of all I found something similar: deep mutable copy of a NSMutableDictionary but it didn't solve my problem. I have a NSMutableDictionary as a template. NSMutableDictionary *mutableDictionaryTemplate = [NSMutableDictionary…
Marty
  • 131
  • 1
  • 10
0
votes
3 answers

Weird behavior of event handlers when deep cloning an object

First off, sorry for not being able to come up with a better title. I tried, though. I have a class like this public class GameBoard : ICloneable { private bool _isCloned; public ObservableCollection BoardPositions {…
lightxx
  • 1,037
  • 2
  • 11
  • 29
0
votes
3 answers

How to Implement deep and shallow copy for NSMutableArray in iOS?

I am trying to implement deep and shallow copy for NSMutableArray, self.oldArray =[[NSMutableArray alloc] initWithCapacity:0]; self.shallowCopy =[[NSMutableArray alloc] initWithCapacity:0]; self.deepCopy =[[NSMutableArray alloc]…
Rooban Ponraj A
  • 281
  • 4
  • 20
0
votes
1 answer

copying a multidimensional array via serialization

I intend to copy a three-dimensional array via serialization, using the following class: public class Serializer { public byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); …
strv7
  • 109
  • 10
0
votes
1 answer

Deep copy of doubly linked list

I am having trouble doing a deep copy of my doubly linked list. This is a homework assignment, so I'd like to know why my code is not working, rather than get working code that I don't understand. Here is my class: #include "textAnalyzer.h" #include…
borabut
  • 27
  • 3
  • 6
0
votes
2 answers

How to deep clone an object list that contains several objects in java?

Say there is an EmployeeList that contains 5 Employee object. I want to perform a clone of that EmployeeList to make a new EmployeeList, and I am wondering how should I do that? So the following is my class Employee: public class Employee { private…
Le Dude
  • 47
  • 1
  • 5
0
votes
2 answers

Is this a right approach to do a deep copy in java for benchmarking memory?

Since System.arraycopy() and clone() does only shallow copying, I wonder if this approach would work for doing a deep copy. ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); long…
Prasanna
  • 2,593
  • 7
  • 39
  • 53
0
votes
1 answer

Assignment/Copy operator overload when class is using itself / deep copy

My problem is, that I have a class which has as an object of itself. When I try to write the assignment or copy method I end in a kind of "classception" the shortened class: class Node { public: Node(QString name, Node *parent = 0); …
Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50