problem about deep-copy-Collection of common programming errors
J Cooper
c++ memory-management deep-copy
Alright, so I’m trying out C++ for the first time, as it looks like I’ll have to use it for an upcoming course in college. I have a couple years of programming under my belt, but not much in the non-garbage-collected world.I have a class, a Node for use in a doubly linked list. So basically it has a value and two pointers to other Nodes. The main constructor looks like Node(const std::string & val, Node * prev, Node * next). The exercise includes a copy constructor that does a shallow copy o
Neil
django django-models override deep-copy
From this question I got the idea of overriding deepycopy in my Django models. I took the code snippet from that question and put it into my model with the following signature:def __deepcopy__(self, *args, **kwargs):However I want to be able to pass ‘field’ and ‘value’ parameters as well, but this doesn’t work. When I invoke:deepcopy(s1, field=’foo’,value=’bar’)with the params attempting to be pulled from the method body using kwargs[‘field’] and kwargs[‘value’], I get the following error:File “
3Pi
c# struct deep-copy default-copy-constructor
I have a struct, MyStruct, that has a private member private bool[] boolArray; and a method ChangeBoolValue(int index, bool Value). I have a class, MyClass, that has a field public MyStruct bools { get; private set; }When I create a new MyStruct object from an existing one, and then apply method ChangeBoolValue(), the bool array in both objects is changed, because the reference, not what was referred to, was copied to the new object. E.g:MyStruct A = new MyStruct(); MyStruct B = A; //Copy of A
d13
javascript function object closures deep-copy
I have function that returns an object:function makeObject() {return { property: “value”}; }I make can new object from it like this:var newObject = makeObject();I have some questions about this:Does newObject reference the original object that was returned by the function, or is it a completely fresh, new object with it’s own properties? If it’s a completely new object, is it then, in a sense, a deep copy of the object returned by the function? What happened to the original object in the functi
Silvae
iphone objective-c memory nsarray deep-copy
Possible Duplicate:deep copy NSMutableArray in Objective-C ? I have two arrays of length 5 with items of a custom class I’ve built. I want to copy the first array into the second. Once copied I want these two arrays to be totally independent (I want to be able to change the first without affecting the second). I have tried several methods to no avail (when I make a change to one, the other is changed as well). They are shown below.1)[[NSArray alloc] initWithArray:self.lifelineList copyItem
WendiKidd
objective-c ios uiscrollview uikit deep-copy
I need to make a deep copy of a UIView containing several subviews. Please help me figure out how to do this? I’ve done some searching on google and SO and not found anything that does what I want. Explanation for those who would like to know why: I have an infinitely scrolling UIScrollView where, of course, the contents repeat. Each ‘set’ of the contents (for example, say 26 UIButtons labeled A-Z) is contained inside one view. This is the view I need to make a deep copy of, so that I can d
Ed L
python complexity-theory deep-copy
I’m trying to improve the speed of an algorithm and, after looking at which operations are being called, I’m having difficulty pinning down exactly what’s slowing things up. I’m wondering if Python’s deepcopy() could possibly be the culprit or if I should look a little further into my own code.
pushpen.paul
python copy deep-copy
I need to manipulate a large list of objects. Now, I need to invoke copy.deepcopy and it raises a RunTimeError: maximum recursion depth exceeded (Its OK when I try it with a smaller list.). My question is: Is there any other way to get the feature of copy.deepcopy which does not have this problem? Regards.
Yenyi
objective-c ios nsmutablearray nsarray deep-copy
I’ve been staring at this code for a while now, but can’t figure out what in the world is wrong. I have a class called SortFilteringController, which manages the different filtering that I have in the system (internal filter, public filter, sort options, etc). Each of these is stored in an array. So I have a convience method, which basically takes any of these arrays, and resets them with some new data.For example, the setInternalFilter, just calls it.- (void) setInternalFilterTerms : (NSArra
user1735787
crash copy-constructor deep-copy
I am having a serious issue trying to locate the bug in my copy constructor for a binary search tree (deep copy). I’ve traced this code over and over and can’t seem to locate the issue. In fact, the whole code works to an extent… when I print the copied tree it is just fine, but I break at the end, which leads me to believe I have some sort of segmentation fault when the destructor is called? This IS a school assignment, and I’d prefer no full function replacement code per-se even if mine is b
Darryl Janecek
c++ crash deep-copy
I am writing some code to implement a deep copy of an object.Here is my code://—————————————————————————#pragma hdrstop#include <tchar.h> #include <string> #include <iostream> #include <sstream> #include <conio.h>using namespace std;//—————————————————————————class Wheel { public:Wheel() : pressure(32){ptrSize = new int(30);}Wheel(int s, int p) : pressure(p){ptrSize =
user2069621
c++ list linked deep-copy doubly-linked-list
I am having trouble doing a deep copy of my doubly linked list. This is a homework assignment, so Id like to know why my code is not working, rather than get working code that I dont understand.Here is my class:#include “textAnalyzer.h” #include <string> #include <iostream> #include <sstream>TextAnalyzer::Node* TextAnalyzer::createNode(const string& word, const int wordFrequency, Node* const previous, Node* const next) { return new Node(word, wordFrequency, previous, next)
sterva7
java multidimensional-array deep-copy
I intend to copy a three-dimensional array via serialization, using the following class:public class Serializer {public byte[] serialize(Object obj) throws IOException {ByteArrayOutputStream b = new ByteArrayOutputStream();ObjectOutputStream o = new ObjectOutputStream(b);o.writeObject(obj);return b.toByteArray();}public Object deserialize(byte[] bytes) throws IOException,ClassNotFoundException {ByteArrayInputStream b = new ByteArrayInputStream(bytes);ObjectInputStream o = new ObjectInputStream(b
EAGER_STUDENT
javascript deep-copy deepclone
Board = function(){var cells = [8];/*** Initializing every cell using numeric format.* */for (var i=0 ; i<8; i++){cells[i] = [8];for (var j=0 ; j<8; j++)cells[i][j] = new Cell(new Position(i,j));}…. }In Another code GameManager.js,var duplicateBoard = Copy.deepCopy(board); board.moveCell(1,2)And for Deepcopying I am using,Ref : http://jsperf.com/deep-copy-vs-json-stringify-json-parsefunction deepCopy(o) {var copy = o,k;if (o && typeof o === ‘object’) {copy = Object.prototype.toS
itsatony
jquery node.js extend deep-copy
I am struggling with deep copies of objects in nodeJS. my own extend is crap. underscore’s extend is flat. there are rather simple extend variants here on stackexchange, but none are even close to jQuery.extend(true, {}, obj, obj, obj) .. (most are actually terrible and screw up the benefits of asnyc code.)hence, my question: is there a good deep copy for NodeJS? Has anybody ported jQuery’s ?
MgSam
javascript deep-copy object-graph
I need a function which makes a deep copy of an object in JavaScript. Each object is part of a larger graph (thus the need for a deep copy function). For example,//Node “class” with references to its parent and children var MyNode = (function () {function MyNode() {this.children = undefined;this.parent = undefined;}return MyNode; })();The graph has no loops. My thought was to do a depth-first-search through the graph and use a dictionary that stores a hash of each Node with its copy. As each nod
Anthony Williams
c++ inheritance constructor assignment-operator deep-copy
I recently revisited the copy constructor, assignment operator, copy swap idom seen here: What is the copy-and-swap idiom? and many other places – The Above link is an excellent post – but I still had a few more questions – These questions are answered in a bunch of places, on stackoverflow and many other sites, but I have not seen a lot of consistency – 1 – Should you have try-catch around the areas where we allocate the new memory for a deep copy in the copy constructor ? (Ive seen it both w
Aaron Fi
javascript deep-copy kineticjs
I have some library code that is cycling endlessly on me.I’m not clear on how to best perform cycle detection and avoidance in javascript. i.e. there’s no programmatic way of inspecting whether an object came from a “this” reference, is there? Here’s the code. Thanks!setAttrs: function(config) {var go = Kinetic.GlobalObject;var that = this;// set properties from configif(config !== undefined) {function setAttrs(obj, c) {for(var key in c) {var val = c[key];/** if property is an object, then add a
Mike Miller
python environment-variables deep-copy
I probably just missed some bit of documentation on how os.environ or copy.deepcopy works, but it appears that copy.deepcopy doesn’t work on os.environ. But if I reconstruct the os.environ into a new dictionary, it works fine. Here’s my example code:import copy import ostcsh_loc = ‘/bin/tcsh’ safe_dict = {} for key in os.environ.keys():safe_dict[key] = os.environ[key]safe_dict[‘SAFE_ENV’] = ‘non-leaked-var’ os.spawnv(os.P_WAIT, tcsh_loc, [tcsh_loc, ‘-c’, ‘echo $SAFE_ENV’]) os.spawnve(os.P_WAIT,
Steve Greatrex
javascript jquery clone deep-copy
Let’s I have next javascript object. Now I want clone it but without some fields. For example I want cloned object without field “lastName” and “cars.age” Input{“firstName”:”Fred”,”lastName”:”McDonald”,”cars”:[{“type”:”mersedes”,”age”:5},{“model”:”bmw”,”age”:10}] } Output (cloned) {“firstName”:”Fred”,”cars”:[{“model”:”mersedes”},{“model”:”bmw”}] } I can do something like var human = myJson var clone = $.extend(true, {}, human) delete clone.lastName _.each(clone.cars, function(car))
timw4mail
javascript deep-copy
I’ve been working on my own javascript library, kis-js. I recently converted it to work with dom selectors like jQuery, but because of javascript copying only references I have this issue: If you call $_ twice, the second time you call it changes the result of the first call.Test Code:<h1>Heading</h1> <a>Anchor</a> <script>var anchor = $_(“a”);var heading = $_(“h1”);console.log(anchor.el); // should be <a>, but it’s <h1> </script>Here’s the source
MWright
c++ pointers const copy-constructor deep-copy
I have an object constructor that takes in a const pointer to a const objectA::A( const B* const ex): m_B(B){};where m_B:const B* const m_B;I am now trying to create a copy constructor and assignment operator I have tried the following without any luck.Copy Constructor:A::A( const A& cpy): *m_B(*cpy.m_B) {}This does not work…how do I approach this? Assignment Operator:A& A::operator=(const A& rhs) {*m_B = *rhs.m_B // I know this won’t work because const cannot be assigned // error
Shigga
c++ arrays dynamic deep-copy
Okay, so the here is things that I still need to do. I am having some serious problems with syntax. I don’t know why I am getting an error when I try to declare a dynamically allocated array. It would be great if I could get some help on this.BabyNames class:Should have as data members:a dynamically allocated array of Data objects an int data member that represents the capacity of the array an int data member to keep track of how many array locations have Data objects in them.Besides one or more
vocaro
java clone copy-constructor deep-copy cloneable
I have some code that performs a deep copy using Object.clone, but I’m trying to rewrite it using the more “acceptable” copy constructor technique. Below are two simple examples of what I’m trying to do, the first using clone and the second using a copy constructor.Deep copy using cloneimport java.util.*;abstract class Person implements Cloneable {String name;public Object clone() throws CloneNotSupportedException {return super.clone();}}class Teacher extends Person implements Cloneable {int cou
Web site is in building