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

How do i deepcopy a list containing Class objects which reference images in Pygame?

I'm trying to re-write a chess game with some improvements and am having problems since i added sprites. In the original game i drew black or white circles with initials to represent the pieces. These were meant to be temporary and were enough to…
AndyM
  • 1
  • 3
-1
votes
1 answer

Why std::move doesn't avoid a second destruction?

I know ordinary std::vector::push_back() will copy the object. I hope this code would only destruct a only once, using std::move() and A(A&&) noexcept to avoid copying. But it doesn't seem to work. Is there any way that I can construct an object…
-1
votes
1 answer

Deep copy source fields into existing destination fields (do not overwrite or change destination's PropertyChangedEventHandler)

I would like to deep copy < MyParameter > par0 into an existing < MyParameter > par1, where some of par1's sub-elements has PropertyChanged event handlers registered, which are not allowed to be overwritten. I have tested several sources like…
Zulu
  • 1
  • 3
-1
votes
4 answers

Is there a way to clone an array which is nested inside another array in an object

I have an obj that looks like this. let obj= { title:"my form", endTIme:"2/20/22", mainList:[ { type:"multiple", checked:false, multiple:[ { optionCheck: false, optionAnswer:"" } …
-1
votes
1 answer

Deep-copy with AutoMapper

I want to create a deep copy of an object. I chose to use the automapper because this way I dont have to edit classes and add there any extra code. Plus I use automapper for mapping my classes to DTOs. On my surprise when I wanted to do a copy…
Kebechet
  • 1,461
  • 15
  • 31
-1
votes
1 answer

Deep copy constructor in C++

The program is aimed to create a deep copy constructor for Foo. Here's the class definition: class Foo { int _cSize; char *_cValues; std::vector _iValues; double _dValues[100]; public: double &dValues(int i) { return _dValues[i]; } …
aurora
  • 67
  • 3
-1
votes
3 answers

Print a dictionary with the given format

Here is my code. It is necessary to output with preservation of text formatting and changes made to the dictionary from pprint import pprint site = { 'html': { 'head': { 'title': 'Куплю/продам телефон недорого' }, …
3Vw
  • 53
  • 7
-1
votes
1 answer

How to generate an independent copy of namespace in below code

Why I cant generate a copy of rst in below code? I need to have a data structure like what you see below and then make independent copies with different values from it. guide me what is my mistake? from copy import deepcopy class rst: a=2 …
BijanSeif
  • 39
  • 5
-1
votes
2 answers

Deep copy vs Shallow copy on iOS

What is the difference between deep copy and shallow copy on iOS world?? Please answer to this question very detailized!! e.g a piece of code class A { var name: String init(name: String) { self.name = name } } var a1 =…
-1
votes
2 answers

deep copy without using serialize/deserialize

How deep copy a class object without doing serialize/deserialize? For example public class Book { public string Chapter { get; set;} public int Page { get; set;} } public void Main () { Book newBook = new Book(); newBook.Chapter =…
Nan Zheng
  • 3
  • 2
-1
votes
1 answer

When given a list of the same instance of a class, how does deepcopy behave

When given a list of the same instance of a class, how does deepcopy behave? Does it keep looping through the list and calling copy() or does it create a new instance and assign it to all of the old instances?
user10725691
-1
votes
1 answer

Why Deepcopy in Python not creating new objects for single int values?

I need some clarification on this concept here, I am trying out .deepcopy() in python and I have read that: A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. However,…
jaideep
  • 13
  • 1
  • 5
-1
votes
2 answers

Javascript deep copy using JSON.parse and JSON.stringify

Is the below method a foolproof way of deep copying an object in Javascript i.e. even for very deeply nested objects/arrays ? let newObj = JSON.parse(JSON.stringify(obj));
copenndthagen
  • 49,230
  • 102
  • 290
  • 442
-1
votes
1 answer

In Python, to make two or more copies of a mutable object, is there a way to do that other than a deepcopy of a deepcopy (with memo)?

I was reading up on deepcopy, and due to the use of memoization, it looks like deepcopies of the same mutable object all refer to the same object that resulted from the first deepcopy (if that makes sense). (Question and code below was inspired by…
dasheea
  • 3
  • 1
  • 1
-1
votes
1 answer

Difference on List.add(list) and List.add(stringbuilder.toString)

I am working on the N Queens problem and the Generate Parentheses problem. When you want a List> as the result, and you want to add the List to it, you need to do a deep copy right? Like result.add(new…