Re: ByRef v ByVal

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 08/02/04


Date: Mon, 2 Aug 2004 08:54:39 -0500


"Tony Proctor" <tony_proctor@aimtechnology_NOSPAM_.com> wrote

> Re-reading the ping-pong replies so far suggests (to me) that you
> both know what "aliasing" is, and why it affects compiler optimisation, but
> are simply describing it in different ways.
...
> For the record: aliasing is a situation where two or more variables
> reference the same physical location in memory.
...
> For instance: the same value being passed via 2 different
> arguments to the same procedure, or even a variable with global scope being
> passed via 1 argument.

Where do you see anything about using two differnt variables in his statement:

  Passing a parameter using a ByRef is called "aliasing"

His position was, simply using ByRef on a procedure parameter was cause
enough not to check that box. Do you agree with that position? That is what
he said, MS's caution was about:

"you should be careful not to check this option if your program PASSES
arguments ByRef, since the optimizations could cause the program to execute
incorrectly."

Keep in mind, it is not the passing of the variable (global or not) that is the
problem, it is accessing the same memory location in two different ways, inside
a procedure that can cause problems. So even passing in a global variable will
not be a problem if the global variable itself is not used in the routine. In that
manner, simply passing in a variable ByRef is not a problem, and contrary to
what he said, it is not called aliasing (as indicated by the optimizing switch).

LFS



Relevant Pages

  • Re: ByVal vs ByRef
    ... > Since using ByRef passes the memeory pointed to a variable, ... passing a long integer byref pushes the address of the ... Passing it byval causes vb to do the deref, and push the 4-byte value onto ... Passing a string ByVal to a VB procedure ...
    (microsoft.public.vb.general.discussion)
  • Re: a byval-byref-optional-generic oddity
    ... "AMercer" schrieb:>> You're actually passing the pointer to the object, ... > question involved generics, optional parameters, and ByVal vs ByRef. ... > End Sub ...
    (microsoft.public.dotnet.languages.vb)
  • Re: D3 odbc and .Net, almost there!
    ... that he was passing values ByVal instead of ByRef in his VB.NET code, ... is one of the issues .NET was designed to fix - but nothing will fix ... what they will and will not support. ...
    (comp.databases.pick)
  • Re: ByRef v ByVal
    ... A variable passed ByRef, and altered in the called routine, had better ... > M$ shows one example of aliasing inside a proc and suggests this can cause ... since the optimizations could cause the program to execute ...
    (microsoft.public.vb.general.discussion)
  • Re: Heres one for you rick
    ... extra ref, but if passing ByVal, a change in type makes no difference. ... ByRef as object and set it to nothing inside the function it doesn't ... I just did another test, with Class1 and ITest, an interface. ...
    (microsoft.public.vb.general.discussion)