reference

Array of object references

折月煮酒 提交于 2019-12-24 15:34:40
问题 In Java, let a custom object o is of type CustomObject . Then CustomObject o2 = o; would make a reference without copying the contents of o to o2 . But will this behaviour remain for an array of CustomObject s: CustomObject[] os = new CustomObject[2]; os[1] = o; os[2] = o; Will os[1] and os[2] be references or they will be direct copies of o and thus separate objects? 回答1: Well, you actually mean os[0] and os[1] as arrays are 0-based in Java... but yes, they'll be references. Both array

Why a slice []struct doesn't behave same as []builtin?

余生颓废 提交于 2019-12-24 15:25:15
问题 The slices are references to the underlying array. This makes sense and seems to work on builtin/primitive types but why is not working on structs? I assume that even if I update a struct field the reference/address is still the same. package main import "fmt" type My struct { Name string } func main() { x := []int{1} update2(x) fmt.Println(x[0]) update(x) fmt.Println(x[0]) my := My{Name: ""} update3([]My{my}) // Why my[0].Name is not "many" ? fmt.Println(my) } func update(x []int) { x[0] =

Multiple references to a variable in JavaScript

北城以北 提交于 2019-12-24 15:18:55
问题 Is there any way for a variable to act as a reference to another variable? Could I have multiples variable all hold the same information regarding a single piece of data? For example: var foo = "data"; var bar = foo; // I want this to set both foo & bar to null foo = null; console.log(bar); // However, bar is still set to "data" In C or C++ you're able to get this desired behavior with pointers; having two variables reference the same location in memory. Is there some way to mimic this

Object reference issue

放肆的年华 提交于 2019-12-24 15:15:02
问题 I am facing a strange problem in JavasSript. There are three variables (declared as var ), they all store an object; say var object1 , object2 and object3 . Ok, so what I do now is I assign object2=object1 and object3=object1 . And when I add something to object2 , it automatically gets added to object3 . Strange? :| Please help. I think I am missing some basic funda here, but I am not able to catch it. 回答1: So how is that strange? You pass reference to the object and do not clone the object.

Add DLL reference to visual studio macros

不想你离开。 提交于 2019-12-24 15:09:56
问题 I need to create a lot of macros in visual studio the probelem is I do not know visual basic that good. What I have been doing so far is: Create the algorithm "Code" I plan to use on C# on a console application. I complile it then decomplite it with reflector into visual basic. When I decompile the code I lose the comments plus sometimes I have to refer back to the code and it becomes hard to manage. I am tired of compiling and decompiling plus I have to make a few twick every now and then. I

Recursive Insert for Binary Tree

半世苍凉 提交于 2019-12-24 14:25:55
问题 I'm working on code for insertion into a binary search tree. It works for the first node I insert, making it the root, but after that it doesn't seem to insert any nodes. I'm sure it's a problem with setting left/right references, but I can't quite figure it out. Please help! //params: key of node to be inserted, parent node public void insert(int newKey, TreeNode parent){ //if the root of the tree is empty, insert at root if(this.getRoot() == null){ this.root = new TreeNode(newKey, null,

How do I change a value argument from within an event handler?

妖精的绣舞 提交于 2019-12-24 13:52:53
问题 I’m passing a bool to a method in another class by reference, so that I can change it (-the original argument) from within the method. I also want an event (which is subscribed to by that method) to be able to change it. Doing this: class myCheckBox : CheckBox { bool b1; public myCheckBox(ref bool b) { b1 = b; this.CheckedChanged += new EventHandler(myCheckBox_CheckedChanged); } void myCheckBox_CheckedChanged(object sender, EventArgs e) { b1 = Checked; } } doesn’t help, since b1 is only a

C# - struct serialization

我的梦境 提交于 2019-12-24 13:16:47
问题 I have got a small class that I would like to use for serializing structs. I would like to know two things: Performance issue. Since I am passing Object - it passes just a reference, not a copy of the struct? And since I am returning object of type T it also only passes a reference? Correctness issue. Will this serialization work for all structs? I mean - is there a possibility where those methods will not work? public static byte[] ToByteArray(Object obj) { int size = Marshal.SizeOf(obj);

C++ OpenMP Tasks - passing by reference issue

大兔子大兔子 提交于 2019-12-24 13:05:46
问题 I am currently working on a system in which I reading in a file of over ~200 million records (lines), so I am buffering the records and using OpenMP tasks to manage each batch while continuing to process input. Each record in the buffer takes roughly 60μ to process in work_on_data , and will generate a string result. To avoid critical regions, I create a vector for results, and pass record placeholders (that I insert into this vector) by address to the work_on_data function : int i = 0;

How to implement a list of references in python?

梦想与她 提交于 2019-12-24 12:16:15
问题 I'm trying to model a collection of objects in python (2). The collection should make a certain attribute (an integer, float or any immutable object) of the objects available via a list interface. (1) >>> print (collection.attrs) [1, 5, 3] >>> collection.attrs = [4, 2, 3] >>> print (object0.attr == 4) True I especially expect this list interface in the collection to allow for reassigning a single object's attribute, e.g. (2) >>> collection.attrs[2] = 8 >>> print (object2.attr == 8) True I am