pass-by-reference

Is returning a whole array from a Perl subroutine inefficient?

I often have a subroutine in Perl that fills an array with some information. Since I'm also used to hacking in C++, I find myself often do it like this in Perl, using references: my @array; getInfo(\@array); sub getInfo { my ($arrayRef) = @_; push @$arrayRef, "obama"; # ... } instead of the more straightforward version: my ...

Is it possible to pass properties as "out" or "ref" parameters?

Hi All, Can I pass a property as an "out" or "ref" parameter if not then why not? e.g. Person p = new Person(); . . . public void Test(out p.Name); ...

How to pass values by ref in Python?

Basically I am using the C++ API of an app, but there is no reference for its python access. One variable is passed by ref, like so: GetPoint ( Point &p, Object obj ) so how can I translate to Python? Is there a pass by ref symbol? ...

Change basic (immutable) types inside a function in Python?

I am using a C++ SDK where there is a function like (it has a python wrapper, but not docs): getPos ( int uvId, float & u, float & v ) const How do I specify in Python so that the passed variables are changed? I tried this example to see if I could modify floats inside a function, but it didn't work, so printed 12.0: def change ( a ...

Does Java pass by reference?

Does Java really support passing by reference? If it doesn't, why do we have the == operator for finding two objects with the same reference? ...

What is the difference between passing by reference in Java and passing a pointer in C?

I have been studying Java for a few months and am now starting to learn C. I am a little confused, I was under the impression that passing an object by reference and passing a pointer to that object were the same thing: I thought the difference was that in Java all passing of objects is done with pointers automatically, where as in C o...

std::for_each, calling member function with reference parameter

I have a container of pointers which I want to iterate over, calling a member function which has a parameter that is a reference. How do I do this with STL? My current solution is to use boost::bind, and boost::ref for the parameter. // Given: // void Renderable::render(Graphics& g) // // There is a reference, g, in scope with the call...

Elegant technique to move items from one array to another

Context: A card game; I want to deal out cards from a deck to each player in the game, in a clean way. This is what I had in mind: public static CardGame.IGame DealAll(this CardGame.IGame objThis, CardGame.Card[] cards) { if (objThis.Players.Length > 0) { for (int i = 0; i < cards.Length; i++) ...

Passing a variable by reference into a PHP extension

I'm writing a PHP extension that takes a reference to a value and alters it. Example PHP: $someVal = "input value"; TestPassRef($someVal); // value now changed What's the right approach? ...

Why won't my Perl function work?

I am having trouble with a function I wrote... sub TemplateReplace { my($regex, $replacement, $text) = @_; $text =~ s/($regex)/($replacement)/gs; } my $text = "This is a test."; TemplateReplace("test", "banana", $text); But it doesn't work. I thought arguments were sent by reference in Perl. Does the line my($regex, $replacem...

Passing an IDisposable object by reference causes an error?

I am trying to create a general method for disposing an object that implements IDisposable, called DisposeObject() To make sure I am disposing an object pointed by original reference, I am trying to pass an object by reference. But I am getting a compilation error that says The 'ref' argument type doesn't match parameter type In ...

Java is NEVER pass-by-reference, right?...right???

I found an unusual Java method today: private void addShortenedName(ArrayList<String> voiceSetList, String vsName) { if (null == vsName) vsName = ""; else vsName = vsName.trim(); String shortenedVoiceSetName = vsName.substring(0, Math.min(8, vsName.length())); //SCR10638 - Prevent export of empty rows. ...

how do i pass EntityManager to @PostUpdate

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method? ...

What's wrong with passing C++ iterator by reference?

I've written a few functions with a prototype like this: template <typename input_iterator> int parse_integer(input_iterator &begin, input_iterator end); The idea is that the caller would provide a range of characters, and the function would interpret the characters as an integer value and return it, leaving begin at one past the last...

Is there a need to pass variable by reference in php5?

With PHP5 using "copy on write" and passing by reference causing more of a performance penalty than a gain, why should I use pass-by-reference? Other than call-back functions that would return more than one value or classes who's attributes you want to be alterable without calling a set function later(bad practice, I know), is there a u...

How do I pass lots of variables to and from a function in Python?

I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of the variable (string, fl...

Changing value after it's placed in HashMap changes what's inside HashMap?

This is a Java related question. If I create a new HashMap and a new List, and then place the List inside the Hashmap with some arbitrary key and then later call List.clear() will it affect what I've placed inside the hashmap? The deeper question here being: When I add something to a hashmap, is a new object copied and placed or is a ref...

JNA Passing Structure By Reference Help

Hi all, I'm trying to use JNA to talk over a USB device plugged into the computer. Using Java and a .dll that was provided to me. I am having trouble with the Write function: C code: typedef struct { unsigned int id; unsigned int timestamp; unsigned char flags; unsigned char len; unsigned char data[16]; } CANMsg; ...

is PHP and C++ the only 2 places that we need to careful about what looks like pass-by-value is indeed pass-by-reference?

is PHP and C++ the only 2 places that we need to careful about passing a simple data type variable as a function argument and the value can be changed? such as $count = 2; foo($count); echo $count; and the 3rd line, echo $count display something other than 2. I only know of PHP and C++ where it can happen. Is there any other place ...

F#: How do I declare and use ByRef semantics on parameters?

I am wraping some SQL Stored Procs with in/out parameters. This of course means I have to do ugly stuff like declare my parameters as by reference and use mutables. How would I do this in F#? ...