Re: Arrays




"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:e1IKr1JCJHA.3668@xxxxxxxxxxxxxxxxxxxxxxx

"Jeff Johnson" <i.get@xxxxxxxxxxx> wrote in message
news:eskZ8yHCJHA.1628@xxxxxxxxxxxxxxxxxxxxxxx
"Bob" <someonw@xxxxxx> wrote in message
news:%23NXUno5BJHA.4932@xxxxxxxxxxxxxxxxxxxxxxx

Thanks Ralph. I guess, I will use loops. By the way, in VB is there
any way of using pointers for arrays, like C or Fortran. If so, then I
can pass the pointer.

VB ITSELF (i.e., built-in VB functions) cannot use pointers. They will
only be useful if you're passing them to API functions. So I would say
"technically" VB can't use pointers, especially when you tack on the
statement "like C or Fortran." Others may want to argue semantics....


I was actually going to reply yesterday (perhaps even the day before) and
say that basically when you pass an array, you ARE passing a pointer. Now
due to VB hiding things and basically making programming easier than it is
with C or Fortran, but anytime you pass a variable (regardless of what is
is), aren't you essentially passing a pointer?

Not necessarily, arguments that are passed by value are copied onto the call
stack. The called function can alter the value of such an argument, but
that does not affect the value of the variable for the caller. When a
function returns, the memory allocated for the call stack is returned to the
system, and any parameters become garbage in unused memory.

When an argument is said to be passed by reference, its address is copied
onto the call stack (rather than its value), and the caller dereferences the
address passed, to get to the value stored there. In these cases changes to
the value made by the callee also affect the value for the caller. (Another
reason to pass by reference, when the parameter is a large structure or an
array, is to save overhead involved in copying significant chunks of memory
onto the call stack.)

In any case, the lines between the two are much, much clearer in C++ than
they are in VB, but to directly answer your question, no, there is a
distinct difference between passing a value and passing a reference. Yes
all parameters are stored in memory and therefore have an address, but a
called function accesses arguments as offsets from the base of its stack,
the caller doesn't explicitly pass their addresses. it pushes parameters
onto the stack


-Mark


btw, I realize VB optimization tricks make this topic somewhat more
involved, but that's nit-picking, isn't t? :-)



Maybe I'm totally off the mark, but isn't a pointer just a memory address
of where a value resides in memory?

--
Mike
Microsoft MVP Visual Basic




.



Relevant Pages

  • Re: HP48 : recursion : more and more slower
    ... CPU and from there into memory. ... So, memory changes, the system goes through all pointers (keeps track ... The stack is just an sequence of pointers. ...
    (comp.sys.hp48)
  • Re: HP48 : recursion : more and more slower
    ... However Available memory are sufficient... ... objects on the stack and you will notice how the whole calc slows ... the system has to keep track of the pointers shown in the "normal ... Is it an internal operation of RPL operating system, ...
    (comp.sys.hp48)
  • Re: Preventing exploitation with rebasing
    ... which would tell us what segments were ... The best way to think of the NDS represntation of pointers is as tokens. ... therefor puts memory addresses (sometimes actual pointers to kernel ... but it turned out to be just a part of my stack.) ...
    (Bugtraq)
  • Re: where does function reside in memory in C++
    ... the pointers point to? ... Is it stack or heap? ... pre-allocates memory and copies the binary ...
    (microsoft.public.dotnet.languages.vc)
  • Re: IntPtr marshal causes exception
    ... I am not passing around pointers or anything ... I am passing a handle to memory. ... >> Any idea why the exception occurs? ...
    (microsoft.public.dotnet.framework.interop)