Re: Pointer vs Reference
- From: Erik Wikström <Erik-wikstrom@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 11:18:17 GMT
On 2007-09-30 07:16, Roedy Green wrote:
On Sat, 29 Sep 2007 22:56:52 GMT, Erik Wikström
<Erik-wikstrom@xxxxxxxxx> wrote, quoted or indirectly quoted someone
who said :
Foo f1 = new Foo();
Foo f2 = f1;
While it does not exactly take the address of the object referred to by
f1, it does create a new reference (pointer) that points to the same object.
In assembler, what that does in allocate space for a new Foo object on
the heap somewhere. It puts the 32-bit address of that object in f1, a
local variable allocated on the stack frame.
Then it copies the pointer value from f1 and stores it in f2.
No reference is created, except on the initial allocation.
Removing comp.lang.c++ form the discussion since it is becoming Java only.
Oh, I see, I was under the impression that f1 was a reference. Just out
of curiosity what is a reference in Java? Does f1 (and later f2) point
to a reference which refers to the Foo object, or is the Foo object the
reference (which would be quite counter intuitive)?
--
Erik Wikström
.
- Follow-Ups:
- Re: Pointer vs Reference
- From: Lew
- Re: Pointer vs Reference
- Prev by Date: Re: Singly Linked LIst and Objects Newbie Question
- Next by Date: do I need "volatile" for HashMap? when I apply ReentrantReadWriteLock on it.
- Previous by thread: Re: Pointer vs Reference
- Next by thread: Re: Pointer vs Reference
- Index(es):
Relevant Pages
|
|