Re: How java passes object references?
pek wrote:
OK. Let my start by saying some assumptions I made:
A)I thought that everything is stored in memory while a program is
executing. I just found out that there are two different "places", the
stack and the heap. So heap is the actually memory. What is stack?
A stack is exactly the data structure you learned about in your basic
data structures class. CPUs have for a very long time supported this
type of structure directly with hardware.
When you get into compilers and linkers, you'll see how the stack is
used to store return values and arguments for methods (subroutines).
It's simple, but would take a bit of time to actually type out and
explain. Can you ask a professor for a quick look ahead lecture? Or
maybe borrow a book (library?) on compliers and linker programs and read
through the basics?
B)That C++ has only one way of pass-by-reference. A friend of mine
told me that C++ has two: using * and using &. He said something about
pointers and references. I didn't quite get it.
Your friend is basically correct. Technically, pointers are passed by
value. A pointer *is* a reference, however, so you can accomplish the
same thing as pass by reference with a pointer.
And to complicate further, you can pass a pointer to a pointer, or a
reference to a pointer.... (but not in Java... at least not directly).
Saves a space in the local variable registers of the function for h.
When you say registers, are you talking about CPU registers? Or am I
going too far?
Yup, literal CPU registers. Or maybe some close equivalent -- modern
designs use cache as a near equivalent of a register.
So, for memory bits we have: stack, heap, text segment (code), register
file, cache, ... how about memory mapped segments ... virtual memory
(backing store), .... io buffers (I mean in hardware, not main memory)
.... IO space ... then there's networked storage.... :). Having fun yet?
OK, I totally agree. No fanciful terms.
-- pass non-pointer by value
-- pass pointer by value
-- pass non-pointer by reference
-- pass pointer by reference
This opened my eyes.. :P
And Java only uses the first two.