|
 |
Warp wrote:
> Invisible <voi### [at] dev null> wrote:
>> In Java, if you ask for an array of Pixel objects (i.e., "Pixel[]"),
>> what you get is an array of *pointers* to Pixel objects.
>
> I think that in Java it's not completely correct to call them "pointers".
What Warp said is indeed the standard terminology in textbooks that talk
about the stuff.
Basically, an "address" is a location indicator the hardware understands.
(Phrased that way to make "disk address" and "virtual address" and "mapped
address" all fall under the name "address".)
A "pointer" is an address with a type. "int*" is a pointer, not an address.
A "reference" is an opaque pointer to an allocated object that may or may
not be an address.
> Moreover, in C and C++ objects cannot be moved in memory behind the scenes
> because there may be pointers pointing to them, and hence moving an object
> would break the pointers (and thus the entire program). In Java, however,
> objects can be moved in memory without breaking any existing references to
> them, if the references are not raw memory addresses but something smarter
This however is not *quite* true. C# and (I think) Java both store
references as pointers internally, without any additional per-reference
overhead. What lets objects be moved and GCed is the fact that the compiler
has generated information about where the pointers are in each type and that
information is reliable (i.e., no unions of references and integers, for
example). One doesn't need extra indirections. One simply needs to know
whether any given 4-byte field is a pointer or an integer, which can be
deduced from information left for the runtime by the compiler, or basically
what C++ might call RTTI.
The savings that C++ and C save are not storing pointer information for each
class (and in C there really isn't any corresponding bit of info), not
tracking auto pointers to the heap, and so on. I.e., there's less
compile-time space used, and it lets C++ classes with no vtable not need
extra info somewhere saying what bits are pointers.
The original versions of Smalltalk, however, did indeed use the extra
indirection. You could have 2^15 objects at a time, even if you had
megabytes of memory, and there was an extra table somewhere that held the
run-time pointer from the index to the object location. (The odd-numbered
pointers were for small integers, hence 2^15 instead of 2^16.)
--
Darren New, San Diego CA, USA (PST)
Serving Suggestion:
"Don't serve this any more. It's awful."
Post a reply to this message
|
 |