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

The object stored into a PHP session gets the wrong value stored

I have created a shopping cart object that works. But when I try to save the object into the session the wrong content of that object is stored. The value that is being saved is the value after the object is cleared from the shopping cart, the empty…
SocketM
  • 564
  • 1
  • 19
  • 34
-1
votes
1 answer

deepcopying function variable gives unexpected results

I have an object that I create using the following function local function newObject(functionVariable) ... functionVariable = functionVariable or nop ... return setmetatable({ ... functionVariable =…
theman
  • 345
  • 1
  • 14
-1
votes
1 answer

Java Simple Deep Copy

I've scoured the internet for a more fundamental solution to Object deep copy that doesn't require serialization or other external Java tools. My question is how do you deep copy objects that have inherited properties and, in addition are aggregated…
Zachary L
  • 21
  • 3
-1
votes
1 answer

C++ Deep Copy Vector Pointer Object

I have a class called Heap that is a Vector of pointers to HeapItem objects vector myHeap; I want to create a deep copy of Heap so that I can delete all the items in the copy without affecting the original Heap. EX: OriginalHeap = new…
Aeisys
  • 367
  • 1
  • 3
  • 13
-1
votes
2 answers

ArrayList (completely deep copy)

Before entering question, I know other than primitive type, everything is stored by its reference number. My java code structure is something like this..... First I have driver, reservation and car classes. The relationship between them is driver is…
-1
votes
1 answer

how to modify objects from a list and return them in a new list

So I am trying to add a tag to those beautiful soup tags. However with this code only last tag of the list will keep the added tag. Previous tags will have it during iteration and then will lose it. Changes are not persistent. import bs4 def…
Danny
  • 344
  • 1
  • 4
  • 15
-1
votes
2 answers

how to write the copy constructor of a class which has a pointer to this class as data member?

here is a simple example of my code class base { protected: int value; public: base(); base(const int); base(const base &); ~base(); ]; class derived:public base { protected: derived *…
642720452
  • 7
  • 2
-1
votes
1 answer

Deep copy of an ArrayList which collects ArrayLists

i need a method that makes a deep copy..it takes as parameter ArrayList>m and makes a deep copy to another ArrayList which collects also ArrayLists... Everything needs to be deep copied.But no loops only recursively... Could…
tlq
  • 887
  • 4
  • 10
  • 21
-1
votes
4 answers

Trying to delete already-deleted pointer in destructor

I have the following class and I am getting an error when the destructor is called and it tries to delete the pointers to a and b. It looks like they don't exist. This is the line of code triggering the problem: unordered_map* SDict =…
user997112
  • 29,025
  • 43
  • 182
  • 361
-1
votes
3 answers

Why the value of same variable in heap of object 1 not reflected in object2?

s(const s& src) { cout<<"Copy\n"; p =src.p; } void disp(int x=0) { *p = x; cout <<"Value at p :"<<*p <
Poorvi
  • 125
  • 8
-1
votes
1 answer

How can I clone a class?

I have the following class class CommandList( HasTraits ): command_nr = Int command_code = Int command_name = Str status = Int settings = None #It will be a list[dic{list[]}] I'm usind copy.deepcopy to clone…
Mokus
  • 10,174
  • 18
  • 80
  • 122
-1
votes
1 answer

array deepcopy instead of reference in perl object

i tried several hours to store a sub array into an object and failed. maybe someone of you can show me how to store a deep copy with perl. sry i dont know if this question is clear, but should be easy to solve... here the example. here the object…
pyr0
  • 377
  • 1
  • 14
-1
votes
1 answer

Overriding the clone method - not working (Java)

I'm writing a search algorithm to solve the 15 puzzle problem in java. When I clone the puzzle states to generate the new possible moves (the daughters) they still alter each other rather than being separate. Here's my clone method: public…
UltraViolent
  • 99
  • 1
  • 2
  • 9
-2
votes
1 answer

Why deep copy with putAll() is invalid in this example?

import java.util.HashMap; public class test { public static void main(String[] args) { HashMap map1 = new HashMap<>(); HashMap map2 = new HashMap<>(); HashMap map3 = new…
-2
votes
1 answer

Without using the copy library create a copy of a nested dictionary (Python)

I've got a map of this form: Weekday -> Object -> Integer I've tried to do this but am getting some issues down the line to do with a key not existing. The error could exist elsewhere in the code. However, could someone perform a little sanity check…
user7880305