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

How to implement two classes for automatic decision over deep and shallow copy?

I have the following design problem: I have a Resource with two sorts of accessors: one is to modify it (let's call it Access) one is for const-like access (let's call it Const_access), but you could say c1=c2 and then c1 will access c2. Given…
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91
0
votes
2 answers

Python list sorting and indexing

I am having issue understanding and solving the following issue with lists, sorting and indexing. Here is the code example: import random as rdm a=[] for i in range(3): a.append([i,rdm.randint(-5,5)]) print a b = sorted(a,key=lambda…
user1532056
  • 117
  • 1
  • 1
  • 6
0
votes
1 answer

How do I copy from a const generic object?

I'm working on a generic circular buffer but have hit a stumbling block when it comes to the copy constructor (see the code example below). using namespace System; /// A generic circular buffer with a fixed-size internal buffer which allows the…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
0
votes
1 answer

Identity of immutable data in the case of deserialization

If objects are immutable it's very easy and efficient to make a deep copy of object - just copy memory pointer of that object. It's also very easy and efficient to do deep equality check - just compare the pointers. But what happens if data comes…
Alex Craft
  • 13,598
  • 11
  • 69
  • 133
0
votes
3 answers

Deep copying array in C... malloc?

I'm trying to make a deep copy of an array in C (originalBoard being the copy): int gy, gx; for (gy=0; gy<9; gy++) { for (gx=0; gx<9; gx++) { …
Live2Enjoy7
  • 1,075
  • 2
  • 11
  • 22
0
votes
2 answers

Understanding the deep copy constructor in Java

I have a main class called Bar that calls the class Foo, and I think I put in a deep constructor correctly The purpose of a deep copy constructor is to copy the contents of one object to another object and changing the copied object shouldn't change…
Dog
  • 595
  • 3
  • 11
  • 20
0
votes
2 answers

How to deep copy string in javascript?

I'm new to JavaScript and have a basic question. I have 2 text fields on a server-generated page, and I want to copy the text value of field 1 to field 2, and then set field 1's value to an empty string. The problem is since JavaScript is doing a…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
0
votes
3 answers

C++ array of wheel on the heap deep copy

Here is my code: //--------------------------------------------------------------------------- #pragma hdrstop #include #include #include #include #include using namespace…
Darryl Janecek
  • 399
  • 4
  • 9
  • 25
0
votes
2 answers

What might be a suitable method to make deep copy of a Collection object in Objective-C?

The copy method only makes a shallow copy, i.e. a new copy of the collection itself, not all the objects storing inside. The book I am studying now suggested to use archive to create deep copy, i.e. use NSKeyedArchiver to save the collection object…
God_of_Thunder
  • 753
  • 3
  • 20
  • 46
0
votes
1 answer

deep copy of Fragment

I am using a Fragment class. I add it using FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Search fragment = new Search(maincontrolActivity.this); …
AMH
  • 6,363
  • 27
  • 84
  • 135
0
votes
1 answer

Making copied images all rotate independently

I think my issue has something to do with deep vs. shallow cloning, which I have not really worked with before, and cannot seem to understand by reading articles(You can tell I'm not a professional programmer). This is a small game I am making and…
Vynlar
  • 55
  • 1
  • 7
0
votes
1 answer

How can I convert a 3d immutable array into a mutable array?

It seems that when I use mutableCopy whilst the first dimension of arrays stays mutable, but all the arrays within the array have become immutable. My current code seems to have no effect, and attempting to edit the array results in an…
Charles
  • 493
  • 7
  • 14
-1
votes
0 answers

Avoid having to deep copy when trying to assign "const Node& inputnode" to member variable of type "Node*"

I'm relatively new to c++. I have a binaryTree class, that contains Nodes. Inside binaryTree, I want the "addleft" method to take in a node (and the potential subtree attached below it) and just "point" the root.left pointer to the "inputnode",…
JohnZ
  • 87
  • 8
-1
votes
0 answers

Which commands/methods return a deepcopy / shallowcopy / original?

"Python usually just assigns. Some commands produce a shallow copy (e.g., slicing, sorted(), dict .get(), ...). A deep copy is produced by copy.deepcopy, np.array and some other commands." How to improve that quote (of mine)? Mainly the second and…
Convexity
  • 99
  • 3
-1
votes
2 answers

I'm confused about how objects in shallow copy and deep copy are referenced

Shallow_Copy foo = [1, 2, []] bar = foo.copy() foo[0] is bar[0] foo[2] is bar[2] True True Does this mean they both reference to the same objects? However, they behave differently when I modify them. bar[0] = 0 print(foo) [1, 2, []]…
Aaron
  • 25
  • 4