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

BeanUtils.cloneBean() deep copy

If all the objects within the bean implement Serializable interface, will BeanUtils.cloneBean() do a deep copy?
hop
  • 2,518
  • 11
  • 40
  • 56
23
votes
6 answers

How to create a Bitmap deep copy

I'm dealing with Bitmaps in my application and for some purposes I need to create a deep copy of the Bitmap. Is there an elegant way how to do it? I tried Bitmap deepCopy = original.Clone(); ,well apparently this doesn't create a deep copy, but…
Biggles
  • 1,306
  • 1
  • 12
  • 22
23
votes
6 answers

How can I make a deep copy in Objective-C?

I'm learning ios development and I'm confused with deep copying in Objective-C. For example,I have three class below. Now I want to deep copy ClassA, can anybody teach me to finish the copy method? A: @interface ClassA : NSObject…
Fantasy
  • 251
  • 1
  • 2
  • 6
22
votes
4 answers

how to do true deep copy for NSArray and NSDictionary with have nested arrays/dictionary?

Question: Is there a way to use existing objective-c methods to do a full deep copy of a NSDictionary or NSArray, that themselves have nested dictionaries or arrays within them? That is I have read the problem may be when it hits a nested…
Greg
  • 34,042
  • 79
  • 253
  • 454
22
votes
4 answers

Is it fine to use JSON.stringify for deep comparisons and cloning?

After attempting several implementations for deep comparison and copying for JSON-serializable objects, I've noticed the fastest often are just: function deep_clone(a){ return JSON.parse(JSON.stringify(a)); }; function is_equal(a,b){ return…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
21
votes
2 answers

Python dictionary deepcopy

I was wondering in how does exactly deepcopy work in the following context: from copy import deepcopy def copyExample: self.myDict = {} firstPosition = "First" firstPositionContent = ["first", "primero"] secondPosition = "Second" …
mandel
  • 2,921
  • 3
  • 23
  • 27
20
votes
2 answers

How can I create a deep clone of a DB object in Django?

I am trying to create a complete copy of a survey instance, which has several sections, and each section has several questions and finally each question has several options. I am using standard django 1.3.1, with MySQL. I need to be able to create a…
Priyeshj
  • 1,295
  • 2
  • 17
  • 32
20
votes
1 answer

How to copy a NSMutableArray

I would simply like to know how to copy a NSMutableArray so that when I change the array, my reference to it doesn't change. How can I copy an array?
Blane Townsend
  • 2,888
  • 5
  • 41
  • 55
20
votes
1 answer

Creating local copy of passed props in child component in vue.js?

In vue.js what is the right way to edit prop without changing parent data? What I mean by that is whenever we pass any property from parent to child in vue.js then if we make any change to that property in child component then the change is also…
Divyanshu Rawat
  • 4,421
  • 2
  • 37
  • 53
20
votes
3 answers

Copy a list of list by value and not reference

To understand why I was getting an error in a program , in which I tried to find the "minor" of a determinant, I wrote a simpler program because my variables were messed up. This function below takes in a 2 * 2 matrix as an input, and returns a list…
Sphener
  • 313
  • 1
  • 2
  • 7
19
votes
1 answer

python multiprocessing arguments: deep copy?

from multiprocessing import Process # c is a container p = Process(target = f, args = (c,)) p.start() I assume a deep copy of c is passed to function f because shallow copy would make no sense in the case of a new process (the new process doesn't…
max
  • 49,282
  • 56
  • 208
  • 355
19
votes
1 answer

Quicker way to deepcopy objects in golang, JSON vs gob

I am using go 1.9. And I want to deepcopy value of object into another object. I try to do it with encoding/gob and encoding/json. But it takes more time for gob encoding than json encoding. I see some other questions like this and they suggest that…
Rohanil
  • 1,717
  • 5
  • 22
  • 47
19
votes
9 answers

Deep copy of List

I'm trying to make a deep copy of a generic list, and am wondering if there is any other way then creating the copying method and actually copying over each member one at a time. I have a class that looks somewhat like this: public class Data { …
thomas1234
  • 599
  • 3
  • 6
  • 15
19
votes
7 answers

How to deep copy a class without marking it as Serializable

Given the following class: class A { public List ListB; // etc... } where B is another class that may inherit/contain some other classes. Given this scenario: A is a large class and contains many reference types I cannot mark B as…
Gaddigesh
  • 1,953
  • 8
  • 30
  • 41
19
votes
1 answer

std::shared_ptr deep copy object

Can't find much on that for C++11 but only on boost. Consider the following class: class State { std::shared_ptr _graph; public: State( const State & state ) { // This is assignment, and thus points to same object …
Ælex
  • 14,432
  • 20
  • 88
  • 129