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

Cloning arrays of objects with Object.assign

I discovered a bug on a project I'm working on that can be replicated by this snippet: const original = [ { value: 1 } ]; function test() { const copy = Object.assign([], original); copy.forEach(obj => obj.value = obj.value +…
Khryus
  • 347
  • 3
  • 12
-2
votes
2 answers

How to iterate through a C# object's properties and update the corresponding property on another object

I have to objects of the same type, one source and one destination. What I'm attempting to do is iterate through the source object properties, and if it has a value, update the corresponding property on the second. I think I have the first…
Cef
  • 661
  • 1
  • 6
  • 26
-2
votes
1 answer

Python dataclass: Forcing a dictionary field to be a deep copy

I am working with a dataclass that contains a dict. I want the dict to be a deepcopy, without having to rely on a post_init call, which would basically void to interest of a dataclass What would be a nice solution ? from dataclasses import…
Milan
  • 1,547
  • 1
  • 24
  • 47
-2
votes
1 answer

Error: In stack of struct in go-lang get overwrite? How can we do deep-copy of struct in golang?

I have created a stack of struct in Go. type Stack struct { stack []Vehicle } I have this struct and method to create a new struct instance:- type Vehicle struct { Name string Quantity map[string]interface{} } function NewVehicle(name string)…
-2
votes
1 answer

List change after copy Python

I'm coding the final part of a clustering program, I want to parse a file like -- COLOR - POINT COLOR ... where COLOR = (R,G,B) POINT = (X,Y) Example: -- (255,0,4) - (0,0) (255,0,4) (0,1) (255,0,4) (0,2) (255,0,4) (0,3)…
-2
votes
7 answers

Questions about a Segmentation Fault in C++ most likely caused by a custom copy constructor

I'm getting a segmentation fault which I believe is caused by the copy constructor. However, I can't find an example like this one anywhere online. I've read about shallow copy and deep copy but I'm not sure which category this copy would fall…
-2
votes
1 answer

Python Class Member Variable Containing OpenCV data initializes as a pointer

I have created a simple Python class that takes two values as arguments when instantiating it (contents and resolution). These arguments are then assigned to class members in the class' __init__ function. For some reason, one of the class members…
MillerMedia
  • 3,651
  • 17
  • 71
  • 150
-2
votes
1 answer

Deep copy vs shallow copy for structs

I had deep dived in some comparisons about deep or shallow copy while passing a struct with primitive and pointer fields. Like: type Copy struct { age int ac *AnotherCopy } type AnotherCopy struct { surname string } func main() { …
-2
votes
1 answer

Why isn't there a deep copy in Perl CORE?

Among the reasons I could think of not implementing a function in Perl's core are: The feature is rarely needed (avoid core bloat). The feature is easy to implement (the user is expected to do it quickly and correctly). The feature is extremely…
U. Windl
  • 3,480
  • 26
  • 54
-2
votes
1 answer

ObservableCollection deep cloning

I've implemented deep cloning of ObservableCollection in order to reset items to It's original state in editable Datagrid, via cancel button. For this I have two collections - one ObservableCollection to bind Datagrid to It, and cloned List to…
Lucy82
  • 654
  • 2
  • 12
  • 32
-2
votes
1 answer

Copy second nested array of objects into first nested array of objects

How can I assign key value from array of object to another array object I would like to assign the key:value pair to the existing array of object from the another array of objects. I have check this thread but it is not working in my case. I have…
TMA
  • 1,419
  • 2
  • 22
  • 49
-2
votes
2 answers

Deep Copying of a JavaScript Object not working when encapsulated within a VueJS computed property

I have a JavaScript object in a Vue instance that is being deep copied into another JavaScript object via a computed property. However for some reason it shallow copies the object in question instead of a deep copy, even though…
-2
votes
1 answer

Binary Search Tree Copy Constructor | C++

BST::BST() { root = nullptr; } BST::BST(const BST& rhs) { root = rhs.root; root->left = rhs.root->left; root->left = rhs.root->left; TreeNode* DeepCopy = new TreeNode; if (root != nullptr) { DeepCopy->info…
Raiin
  • 35
  • 1
  • 6
-2
votes
2 answers

Printing user input from a copy constructor (java)

I am new to java and cannot figure out how to work the copy constructors. Please bear with me. I am trying to get information for shipping packages. I am trying to use the copy constructor to repeat the enter shipping details section. I honestly…
-2
votes
1 answer

How would you write a simple version of copy.deepcopy()?

For nested lists, what would the pseudocode look like so that mylist = [[1,2],[3,[4,5]],6] def mydeepcopy(mylist) >> [[1,2],[3,[4,5]],6] where it returns a completely different list through all layers here is all I can think of def…