Questions tagged [shallow-copy]

A shallow copy of an object is a duplicate that may not be fully independent of the original, in the sense that any references / pointers it holds to other objects refer to the same objects that the original's do. Use this tag for questions regarding implementing or using shallow copying methods.

Shallow copying is a process by which an object is duplicated to create a copy that may not be wholly independent of the original. Also known as "field by field" copying, this differs from deep copying with respect to the treatment of references / pointers to other objects: shallow copying copies the references / pointers held by the original, whereas deep copying makes a deep copy of each referenced object, too. Shallow copying is "shallow" in the sense that it copies only the original object itself, not any appearing deeper in its reference graph.

Related tags

Links

394 questions
-1
votes
5 answers

Shallow copy in java?

As if we pass predefined list to the new ArrayList constructor it will SHALLOW-COPY that list which means reference to that list , so if we modify the new list ,the changes should also tends to modify at the old list .but in this programme it isnot…
sparsh goyal
  • 89
  • 1
  • 7
-1
votes
2 answers

in c# code why below copy didn't work as reference copy?

Below c# code I run in Visual Studio 2019 Mac, I am a little surprise for the result: using System; namespace Test { public struct Point { public int x; private int y; public Point(int x, int y) { …
Penny
  • 606
  • 1
  • 7
  • 15
-1
votes
1 answer

What is the relation between move semantics and deep/shallow copy?

We can implement our own copy constructor if we don't want a shallow copy. So copy constructurs and copy assignment operators are used to implement deep copy. What sort of relation/interaction do move constructors and assignment operators have with…
JohnDo
  • 9
  • 1
  • 2
-1
votes
1 answer

Create a shallow copy without leaking memory and dangling pointer in C++

Or is it not possible, and I have to do a deep copy. Lets say I have an object A, and I want to make a shallow copy of A into B. If I delete A, and A destroys all if its members, then B would have dangling pointers. If A doesn't destroy its…
Blubber
  • 1,375
  • 1
  • 15
  • 32
-1
votes
1 answer

JAVA it does not clone well

I tried to clone the object of Test2 using the "KUROONN" method. I expected the second line of the output to read [0,0], but the real result shows [33,4]. I have no idea why this happens, so can anyone explain this? import…
-1
votes
1 answer

GO - Is array copy a deep copy or shallow copy?

For the below array, var a[2][3]int a[0][0] = 55 a[0][1] = 56 a[0][2] = 57 a[1][0] = 65 a[1][1] = 66 a[1][2] = 67 on performing array copy, a[0] = a[1] Question: Is the array(a[0]) copy a deep copy or shallow copy? After copy, Does a[0] have…
overexchange
  • 15,768
  • 30
  • 152
  • 347
-1
votes
1 answer

keeping lists separate and avoiding shallow copy in python

Here's my pseudo-code: class foo(bar): def __init__(self, aList): bar.__init__(self, aList) self.initialList = aList def clock(self): modify(self.workingList) if(something): self.workingList =…
Tayyar R
  • 655
  • 6
  • 22
-1
votes
1 answer

VB .NET Textbox Shallow Copy into Dictionary

While there are many questions about shallow copy vs. deep copy, I couldn't find one specific to TextBoxes and Dictionaries in VB .NET. I believe my problem is unique enough to deserve it's own thread. In VB .NET I am trying to implement a…
-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
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

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

passing of structure with pointer member in function is shallow copy or deep copy In C

In C++, there is overloaded copy constructor and assignment overloading for a deep copy. Since default available is a shallow copy. In C, the structure which has pointer member, if passed to a function or assigned to already created new struct…
Laxmi Kadariya
  • 1,103
  • 1
  • 14
  • 34
-2
votes
3 answers

How to implement an assignment operator so multiple instances share common data?

I am working on C++11 application. I am implementing assignment operator. I want that if I modify one value after the assignment both objects get modified. Example: Object o1, o2; o1.setId("id1"); o2 = o1; o2.setId("id2"); cout << o1.getId(); …
-2
votes
4 answers

How to reverse shallow copy a javascript array (container)?

Need help creating a custom object type that performs a reverse shallow copy? For example: arrayobj.slice(0) returns a new array object with the same length but each index maintains a reference to the object found at the same index of the original…
Benjamin McFerren
  • 822
  • 5
  • 21
  • 36
-2
votes
2 answers

Jave: trouble with my shallow copy constructor

I have trouble with my java homework. I am making a Matrice class and i have trouble with the shallow constructor that take another Matrice as argument. Public class Matrice implements IMatrice{ private static int numLignes ; private static int…
1 2 3
26
27