Which is better, pass, or not pass by reference?

From: Randell D. (you.can.email.me_at_randelld.at.yahoo.com)
Date: 10/21/03


Date: Tue, 21 Oct 2003 07:04:40 GMT


Folks,

I've asked this before but never got any response but its important and I
thought I'd pitch it again (hopefully a bit clearer)...

One can pass data from one function to another either by passing a copy, or
passing by reference.

My understanding of passing by reference (putting the & before a variable
during the function declaration) means that the original data is used.

My understanding of *not* passing by reference, (thus passing a copy)
literally
means creating a copy of the data contained in my variables - thus doubling
the memory usage for this data... even if its just a temporary while the
function is being executed.

I *believed* (past tense) that one should only pass by reference if they
wanted the child function to change the data and pass the newer values back
to the parent function.

I'm now thinking that this is just a feature and not the only usage. I am
begining to think I should use "pass by reference" nearly all the time in
order to conserve memory (since I won't be creating copies of my variable
data in memory).

Would this be good practice? Am I right that passing by reference means that
my variable data is not duplicated thus using less memory than if I had
passed my variable data as a copy?

-- 
All comments + replies please via the newsgroup,
Thanks,
Randell D.
-
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?


Relevant Pages

  • Re: performance hit using byref or byval?
    ... Byval might be faster if I don't mind the memory ... > You're not actually passing the huge object around when you use byref. ... > you're passing is the reference to the object, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Which is better, pass, or not pass by reference?
    ... > passing by reference. ... > the memory usage for this data... ... Am I right that passing by reference means ... > my variable data is not duplicated thus using less memory than if I had ...
    (comp.lang.php)
  • Re: pointer syntax
    ... > really passing a reference (which is like an old-school pointer, ... > a copy of the primitive's value and passing that. ... build them yourself with pointers. ... mean a var parameter, write a var parameter. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Passing by reference
    ... It depends upon the reason one is passing the reference. ... instantiate all relationships via a constructor so there will always be ... I naturally think of 'getter' methods as 'knowledge ...
    (comp.object)
  • Re: Using ref
    ... the address of a variable that contains a reference to an object, ... the C version is passing the address of a variable that contains the   ... Inasmuch as the specification is unambiguous, there is a single truth. ... Every time he states the incorrect view, I will feel compelled to correct his incorrect statements. ...
    (microsoft.public.dotnet.languages.csharp)