shallow-copy Questions

1

Solved

I learned that when using Object.assign() it extends only the top level object. How can I deeply extend the object? For example, let's say I have the following source object: const source = ...

7

Solved

I've been saving all the data received from services direct to local variable, controller, or scope. What I suppose would be considered a shallow copy, is that correct? Example: DataService.callF...
Beane asked 9/10, 2015 at 17:16

1

Solved

The are several alternatives to make a shallow copy of a list in Python 3.5+. The obvious ones are: some_list.copy() some_list[:] list(some_list) [*some_list] and others... Which method i...
Korte asked 17/12, 2017 at 21:9

9

Solved

It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object. Here's a simple, contrived proof: <?php class A { public ...
Abridgment asked 9/10, 2008 at 4:21

5

Solved

I have two objects of the same type and need to copy property values from one object to another. There are two options: Use reflection, navigate through the properties of the first object and cop...
Cyrillus asked 18/11, 2011 at 11:14

6

Solved

I am a bit new to these two methods of copying one object into the other. I am confused and unable to spot out the major difference between deep copy and shallow copy.. I had gone through a lots of...
Apocarp asked 5/8, 2013 at 19:45

2

Solved

In python, if I have x = y any modification to x will also modify y, and I can do x = deepcopy(y) if I want to avoid modifying y while working on x Say, instead, that I have: myFunc(): r...
Tyrannize asked 3/2, 2017 at 20:18

1

Solved

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 ...
Seeress asked 27/1, 2017 at 4:39

8

Solved

I have a long class with a lot of data members. I want to write a copy constructor for it. But, if I write my own copy constructor, I lose access to the default copy constructor. I just want to rep...
Coxcombry asked 14/9, 2012 at 10:52

3

Solved

If i have a code like this class Student { public string RollID { get; set; } } class Person { public Student student { get; set; } public string Address { get; set; } public string Name { ge...
Nidia asked 8/11, 2016 at 13:27

3

Solved

I am trying to understand the concept of shallow vs deep copy in Java. There is a lot of articles and Q&A about this subject, but whenever I try to implement these concepts in a real Java code,...
Mysia asked 28/7, 2016 at 16:4

1

Solved

I'm looking for a simple way to return a new structure which is a copy of an existing one with some fields changed, without modifying the original. I get that you can use setf to change the data i...
Journalize asked 17/7, 2016 at 13:25

4

Solved

Explanation : we come across some situation in which we need to copy one object to another object. In that case, we probably have two solutions: angular.copy() or angular.extend(). Challenge i am f...
Etymon asked 24/4, 2016 at 19:28

4

Yesterday I asked a question about copying objects in C#, and most answers focussed on the difference between deep copy and shallow copy, and the fact that it should be made clear which of both cop...
Garibold asked 28/7, 2010 at 7:24

4

Solved

I'm taking a class on object oriented programming using C++. In our text it says, If we do not declare a copy constructor, the compiler inserts code that implements a shallow copy. If we do not de...
Osmic asked 22/10, 2015 at 16:58

3

Solved

As I understand it, there are a couple of ways (maybe others as well) to create a shallow copy of a Map in Java: Map<String, Object> data = new HashMap<String, Object>(); Map<String...
Culprit asked 1/3, 2010 at 15:23

2

Solved

Given: class Foo { private: static int cntFoos; //... stuff... public: Foo() { cntFoos++; } ~Foo() { cntFoos--; } }; ... where "stuff" may be any set of properties. (The idea is to have a...

3

Solved

Assuming I have 2 array of different size i.e int arr[] = {0,1,2,3,4,5,6,7,8,9}; int *arr2 = new int[5]; I want to shallow copy some of them, Deep copy equivalent would be int j =0; if(!(i%2))...
Meggs asked 31/7, 2014 at 4:29

7

Solved

I was recently looking into freeing up memory occupied by Java objects. While doing that I got confused about how objects are copied (shallow/deep) in Java and how to avoid accidently clearing/null...
Anthemion asked 2/8, 2013 at 6:12

2

For copying a list: shallow_copy_of_list = old_list[:]. For copying a dict: shallow_copy_of_dict = dict(old_dict). But for a set, I was worried that a similar thing wouldn't work, because saying ...
Oxidate asked 21/4, 2014 at 16:1

4

Solved

I have a general question about deep- and shallow-copy in the context of the pass-by-reference- and pass-by-value-concept of C#: In C# it is a requirement to explicitly create methods that accept ...
Pouter asked 13/4, 2014 at 9:56

1

Solved

Why is shallow-copying a list using a slice so much faster than using list builtin? In [1]: x = range(10) In [2]: timeit x_ = x[:] 10000000 loops, best of 3: 83.2 ns per loop In [3]: timeit x_ =...
Bulwark asked 1/4, 2014 at 20:23

2

Solved

I have an IEnumerable object as: IEnumerable<string> listSelectedItems; Which contains three items. Now i created a new object and want to get all items from listSelectedItems, so i wrote...
Variegate asked 19/10, 2013 at 7:9

2

Solved

In Perl, you can assign to a variable a reference to another variable, like this: my @array = (1..10); my $ref = \@array; And, as it is a reference, you can do something like this and both varia...
Exception asked 6/4, 2013 at 3:35

1

I need to add a UIElement to two different canvases, but one UIElement can only be a child of ONE canvas, so I have to create a ShallowCopy (DeepCopy not needed) of the UIElement. I want to use Me...
Thrall asked 23/11, 2012 at 1:10

© 2022 - 2024 — McMap. All rights reserved.