Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

question--function returns class object(comparing C++ & JAVA)

Thread view: 
Xiaoshen Li - 13 Dec 2005 18:51 GMT
Dear Sir,

I am a little puzzled about a function returning a class object, for
example, suppose I hava a class Money and a method:

Money lastYear(Money aMoney)
{
    Money tempMoney;
    ...
    return tempMoney;
}

Because in C++ the RETURNED is actually a new copy of the object(kind of
like passing by value), here a copy of tempMoney is returned, so after
the statement of return,  the local & temporary object tempMoney will be
destroyed.

Now, if in JAVA, since always passing by reference, if above code is
Java, the RETURNED is the MEMORY ADDRESS of the object tempMoney. So
after the exit of the function, the object tempMoney refering to is
referenced by other variable. So it stays existing. What happens to the
local & temporary variable tempMoney? Will it be destroyed after the
function has finished?

Another question:
In C++,
Money aMoney, bMoney;
..
bMoney = aMoney;

Now bMoney and aMoney are referring to different but identical objects.

But in JAVA,

bMoney = aMoney;

will make bMoney and aMoney refer to the SAME object. Is this correct?
Can I make assignment("=") in JAVA behaves like in C++?

Thank you very much.
Eric Sosman - 13 Dec 2005 22:54 GMT
Xiaoshen Li wrote On 12/13/05 13:51,:
> Dear Sir,
>
[quoted text clipped - 19 lines]
> local & temporary variable tempMoney? Will it be destroyed after the
> function has finished?

   tempMoney is not an object; it is a reference to
a Money object.  When the lastYear() method returns,
the tempMoney variable ceases to exist, but nothing
happens to the Money object it once referred to.

   In C terms, tempMoney is a pointer and the Money
object is the thing it points to.  Destroying the
pointer doesn't destroy the pointed-to object.

> Another question:
> In C++,
[quoted text clipped - 9 lines]
>
> will make bMoney and aMoney refer to the SAME object. Is this correct?

   Yes.

> Can I make assignment("=") in JAVA behaves like in C++?

   I don't know C++, but from your description it sounds
like you want a copy of the object that aMoney points to.
Unaided `=' will not do this.  If you actually need a copy
(that is, a new Money object initialized with all the same
contents as the old one), the simplest approach is to give
the Money class a "copy constructor" that does the job:

    Money(Money oldMoney) {
       amount = oldMoney.amount;
       currency = oldMoney.currency;
       exchangeRate = oldMoney.exchangeRate;
       ...
    }

Now you can write `bMoney = new Money(aMoney)'.

   Other possibilities exist, with somewhat different
semantics.  You can write `bMoney = aMoney.clone()' if
Money implements the Cloneable interface, and this will
work better if Money has subclasses.  However, Cloneable
has some drawbacks and is not something to be added
without careful consideration.  You could also serialize
a Money object and then deserialize it to create another,
but that smacks of perversity.  And there are probably
more possibilities I haven't thought of.  But a copy
constructor is certainly the simplest approach, so use
it if it meets your needs.

Signature

Eric.Sosman@sun.com

Eric Sosman - 13 Dec 2005 23:05 GMT
Eric Sosman wrote On 12/13/05 17:54,:
> [...]
> You can write `bMoney = aMoney.clone()' [...]

   Sorry; that should have been

    bMoney = (Money)aMoney.clone()

Signature

Eric.Sosman@sun.com

ricky.clarkson@gmail.com - 14 Dec 2005 01:25 GMT
Java and C are both pass by value only.  However, the possible values
differ.

In Java, you cannot have a 'stack object'.  Within a method:
Object object=new Object();

The Object resides on the heap.  Only the variable, object, resides on
the stack.

So this is somewhat related to:

void *pointer=malloc(100);

So the *value* passed to a method is the reference (a reference is a
pointer [1] ).

Tony Morris, the guy who wrote JTiger, wrote something on this. [2]

[1]
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#106237
[2] http://jqa.tmorris.net/faq/GetQAndA.action?qids=37&showAnswers=true
Andrew McDonagh - 13 Dec 2005 23:05 GMT
> Dear Sir,
>
[quoted text clipped - 7 lines]
>     return tempMoney;
> }

this code means there is a Local Reference called 'tempMoney' which
points to an instance of the Money class (i.e a Money object).

References in Java have scope, the objects they point to do not.

So in the code above, the 'tempMoney' reference certainly does go out of
scope when this method returns. But the Object that the 'tempMoney'
Reference pointed too, does not because they can not.

In Java, when an object has no references pointing to it, it 'becomes
eligible for garbage collection'.  Worth Google-ing this term as its a
whole thread of discussion just about that.

Java References are not like C++ References nor Pointers. They don't
point to memory addresses per se. And you certainly can't get or do
pointer arithmetic with them.

> Because in C++ the RETURNED is actually a new copy of the object(kind of
> like passing by value), here a copy of tempMoney is returned,

There's no copying of the Object that the reference pointer too - its
still the same object. However, a new Reference will be created if the
return value is assigned to a reference.

As in..

Money someMoney = lastYear(otherMoney);

Here 'someMoney' points to the SAME object that the 'tempMoney' pointed
too. But someMoney is a new Reference.

> so after the statement of return,  the local & temporary object tempMoney will be
> destroyed.

no see above

> Now, if in JAVA, since always passing by reference, if above code is
> Java, the RETURNED is the MEMORY ADDRESS of the object tempMoney.
> So after the exit of the function, the object tempMoney refering to is
> referenced by other variable. So it stays existing. What happens to the
> local & temporary variable tempMoney? Will it be destroyed after the
> function has finished?

no see above.

> Another question:

> In C++,
> Money aMoney, bMoney;

In Java we have too....

Money aMoney = new Money();
Money bMoney = new Money();

> ...
> bMoney = aMoney;
>
> Now bMoney and aMoney are referring to different but identical objects.

its been 5 years since I've done any C++ but are you sure about this
statement?  Seems wrong to me....

I thought in C++ this means that bMoney is a (C++) reference to aMoney

> But in JAVA,
>
> bMoney = aMoney;
>
> will make bMoney and aMoney refer to the SAME object. Is this correct?

yes.

It also means that the object that bMoney reference pointed too, now has
no references pointing to it and so its eligible for garbage collection.

> Can I make assignment("=") in JAVA behaves like in C++?

Not sure I understand what you want...

> Thank you very much.

No problem glad to help
zero - 14 Dec 2005 13:20 GMT
Andrew McDonagh <news@andrewcdonagh.f2s.com> wrote in news:dnnk43$59d$1
@news.freedom2surf.net:

>> ...
>> bMoney = aMoney;
[quoted text clipped - 5 lines]
>
> I thought in C++ this means that bMoney is a (C++) reference to aMoney

nope, the statement is correct.  It would be a reference if it were:

Money& cMoney = aMoney;

Here you can say cMoney is of type "Money&", which is a reference type.  
Note this is quite different from

Money cMoney;
cout << &cMoney; // output the address of cMoney

Signature

Beware the False Authority Syndrome

Andrew McDonagh - 14 Dec 2005 19:42 GMT
> Andrew McDonagh <news@andrewcdonagh.f2s.com> wrote in news:dnnk43$59d$1
> @news.freedom2surf.net:
[quoted text clipped - 18 lines]
> Money cMoney;
> cout << &cMoney; // output the address of cMoney

oh yes - its coming back now - cheers.
J. Verdrengh - 14 Dec 2005 11:41 GMT
> Now, if in JAVA, since always passing by reference, if above code is Java,
> the RETURNED is the MEMORY ADDRESS of the object tempMoney. So after the
> exit of the function, the object tempMoney refering to is referenced by
> other variable. So it stays existing. What happens to the local &
> temporary variable tempMoney? Will it be destroyed after the function has
> finished?
Class instances are created on the heap and are therefore not destroyed
after exiting a function.
Local variables (a reference in your case) are stored on the stack and
therefore are destroyed when exiting the function.
When no more references to an instance exist, Java will garbage collect the
instance (==remove it from the heap)

> Another question:
> In C++,
[quoted text clipped - 9 lines]
>
> will make bMoney and aMoney refer to the SAME object. Is this correct?
yes

> Can I make assignment("=") in JAVA behaves like in C++?
yes, you can use bMoney = (Money)aMoney.clone();
See another recent thread of this newsgroup for extra info on using
.clone().
zero - 14 Dec 2005 13:31 GMT
> Dear Sir,
>
[quoted text clipped - 19 lines]
> local & temporary variable tempMoney? Will it be destroyed after the
> function has finished?

In java, what is returned is actually a reference, not exactly the memory
address - but you can see it that way, it can make it easier to understand if
you come from C++

You should remember that in Java, all variables of class types are in fact
references, which are similar (but not identical) to C++ pointers.  So, if the
above code were Java, it would be the same as the C++ code:

Money& lastYear(Money *aMoney)
{
  Money* tempMoney = new tempMoney();
  // ...
  return tempMoney;
}

So in java, all references to objects (not primitives) are similar to pointers.  
There is no way to have objects like in your C++ code above.

As for the memory issues, the local reference tempMoney gets out of scope (is
deleted) but the object (memory space) it points to remains, and is returned to
the calling function.

> Another question:
> In C++,
[quoted text clipped - 10 lines]
> will make bMoney and aMoney refer to the SAME object. Is this correct?
> Can I make assignment("=") in JAVA behaves like in C++?

No, because (see above) there is no way to make objects like that.  Again, if
you look at the above code as if it were Java, it would be translated to C++ as
such:

Money *aMoney, *bMoney;
...
bMoney = aMoney;  // both point to the same object in memory

As an aside, using Java references and C++ pointers is more memory efficient
than using C++ objects - so you probably shouldn't be asking for a way to use
C++ style objects in Java anyway :-)

Signature

Beware the False Authority Syndrome

Xiaoshen Li - 14 Dec 2005 12:32 GMT
>>Dear Sir,
>
[quoted text clipped - 4 lines]
>>     return tempMoney;
>>}

> In java, what is returned is actually a reference, not exactly the memory
> address - but you can see it that way, it can make it easier to understand if
[quoted text clipped - 44 lines]
> than using C++ objects - so you probably shouldn't be asking for a way to use
> C++ style objects in Java anyway :-)

Sorry. I cannot understand it. I thought putting a copy constructor
inside java class Money will do the job, as some repliers suggested.

(Java code:)
Money aMoney, bMoney;
aMoney = new Money();
bMoney = new Money(bMoney);  //now aMoney, bMoney refer to two identical
but different objects on the heap.

Further, could you explain a little more about "C++ objects" and "C++
pointers"?
(C++ code:)
Money *aMoney = new Money();
Money bMoney;

now aMoney is a pointer pointing to an heap object instance of class
Money. BUT bMoney is an object on stack. Is this correct? bMoney is "C++
object" you called above? Thank you.
zero - 14 Dec 2005 16:45 GMT
> Sorry. I cannot understand it. I thought putting a copy constructor
> inside java class Money will do the job, as some repliers suggested.
[quoted text clipped - 4 lines]
> bMoney = new Money(bMoney);  //now aMoney, bMoney refer to two
> identical but different objects on the heap.

yes actually that will do it - but you have to be careful if you're using
compound classes (ie classes that contain references to other objects).

For example:

<java code snippet>

class SomeClass
{
  private int attribute;

  public SomeClass()
  {
     attribute == -1;
  }

  public void setAttribute(int i)
  {
     attribute = i;
  }

  public int getAttribute()
  {
     return attribute;
  }
}

class Money
{
  int amount;
  SomeClass someClass;

  public Money()
  {
     amount = 0;
     someClass = new someClass(); // attribute = -1;
  }

  public Money(Money old)
  {
     this.amount = old.amount; // safe
     this.someClass = old.someClass; // dangerous!
  }
}

Money aMoney = new Money();
Money bMoney = new Money(aMoney);

bMoney.someClass.setAttribute(5);

if(aMoney.someClass.getAttribute() ==
 bMoney.someClass.getAttribute())
    System.out.println("Error!");
</java code snippet>

Here you will have two different objects aMoney and bMoney in memory,
however - and this is something a lot of people make mistakes against -
when changing bMoney.someClass you're also changing aMoney.someClass!!

Why?  Because aMoney.someClass and bMoney.someClass point to the same
object in memory, even though aMoney and bMoney are different objects.  
This is because the copy constructor has an error: it makes the someClass
reference in the new object point to the same memory space as someClass
in the old object.

This is a very dangerous and often overlooked mistake.

> Further, could you explain a little more about "C++ objects" and "C++
> pointers"?
[quoted text clipped - 5 lines]
> Money. BUT bMoney is an object on stack. Is this correct? bMoney is
> "C++ object" you called above? Thank you.

Yes that's what I meant.  I haven't studies heaps & stacks in detail, so
I kinda make up my own words ;-)  Here, bMoney is the name of the actual
object in memory, while aMoney is actually the name of a pointer to an
object in memory.  In Java, every variable (except for primitives) is a
pointer to an object - or actually a reference, but it looks a lot like a
pointer to C++ programmers.

Signature

Beware the False Authority Syndrome

Xiaoshen Li - 14 Dec 2005 14:04 GMT
> For example:
>
[quoted text clipped - 59 lines]
>
> This is a very dangerous and often overlooked mistake.

I see. I will change the copy constructor of class Money to:
    public Money(const Money old)
    {
        this.amount = old.amount;
        this.someClass = new SomeClass(old.someClass);
    }

Of course, I need to put a copy constructor inside class SomeClass.

I think this will do the job. Thank you very much!
Andrew McDonagh - 14 Dec 2005 19:46 GMT
>> For example:
>>
[quoted text clipped - 70 lines]
>
> I think this will do the job. Thank you very much!

the only question is why do you need to do this at all?  yes its common
in C++ to have and use a copy constructor, but less so in Java.

You should find yourself needing to clone (which is what you are doing)
only once in a while - not as a standard rule.
Xiaoshen Li - 14 Dec 2005 17:57 GMT
> the only question is why do you need to do this at all?  yes its common
> in C++ to have and use a copy constructor, but less so in Java.
>
> You should find yourself needing to clone (which is what you are doing)
> only once in a while - not as a standard rule.

Could you elaborate why copy constructor is so common and important in
C++ while in java it is not so important? Thank you very much.
Alun Harford - 14 Dec 2005 22:09 GMT
> Could you elaborate why copy constructor is so common and important in C++
> while in java it is not so important? Thank you very much.

(I'm not the OP but here goes)

Firstly, I should point out that creating a copy constructor in Java is
"wrong" - you should implement the Cloneable interface and override the
clone() method of Object.

The primary use for copy constructors in C++ is to create a copy of an
object that is passed by value to your function. Since all Java Objects are
passed by reference, this is not required.

Alun Harford
Andrew McDonagh - 14 Dec 2005 22:36 GMT
>>Could you elaborate why copy constructor is so common and important in C++
>>while in java it is not so important? Thank you very much.
[quoted text clipped - 4 lines]
> "wrong" - you should implement the Cloneable interface and override the
> clone() method of Object.

> The primary use for copy constructors in C++ is to create a copy of an
> object that is passed by value to your function. Since all Java Objects are
> passed by reference, this is not required.
>
> Alun Harford

Thanks!  saved me typing!
Andrew McDonagh - 14 Dec 2005 22:38 GMT
>>> Could you elaborate why copy constructor is so common and important
>>> in C++ while in java it is not so important? Thank you very much.
[quoted text clipped - 12 lines]
>
> Thanks!  saved me typing!

Aside from this major point of not needing copy constructors in java, we
rarely want to have a cloned object either - sometimes, but rarely.
Thomas Hawtin - 14 Dec 2005 23:08 GMT
>>Could you elaborate why copy constructor is so common and important in C++
>>while in java it is not so important? Thank you very much.

> Firstly, I should point out that creating a copy constructor in Java is
> "wrong" - you should implement the Cloneable interface and override the
> clone() method of Object.

There is only need to implement Cloneable if you are going to use the
Object implementation of clone. There is not a pressing need to make
clone public (or add package private access when you override). Prior to
1.5, using a different method allows a useful return type. Using
Object.clone has dangers (admittedly, as does copying lots of fields one
 by one).

> The primary use for copy constructors in C++ is to create a copy of an
> object that is passed by value to your function. Since all Java Objects are
> passed by reference, this is not required.

ObPedantry: It's object references passed by value.

In C++ it's not just passing to your functions where values are copied,
also using, say, the collections of the C++ standard library copies.

Because Java uses garbage collection, the use of immutable types is
trivial. C++ will do implicit copying. In Java where we have types that
fall between immutable values and full-grown "reference objects" with
meaningful identities, then we need to remember to explicitly copy. For
instance when returning a List value object from a public method.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Chris Smith - 18 Dec 2005 19:12 GMT
> There is only need to implement Cloneable if you are going to use the
> Object implementation of clone. There is not a pressing need to make
> clone public (or add package private access when you override). Prior to
> 1.5, using a different method allows a useful return type. Using
> Object.clone has dangers (admittedly, as does copying lots of fields one
>   by one).

Then again, using Object.clone() is the only reasonable way to get
correct object copying behavior in a non-final class with accessible
(protected or public) constructors.  That's the fundamental reason to
use clone() instead of a copy constructor anyway... so yes, I'd say that
implementing Cloneable is fairly important.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Thomas Hawtin - 18 Dec 2005 19:58 GMT
> Then again, using Object.clone() is the only reasonable way to get
> correct object copying behavior in a non-final class with accessible
> (protected or public) constructors.  That's the fundamental reason to
> use clone() instead of a copy constructor anyway... so yes, I'd say that
> implementing Cloneable is fairly important.

You cannot assume that it is going to make sense to do a bitwise clone
of subclass fields. So in general, subclasses will need to override the
copy method, even if Cloneable is implemented.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Chris Smith - 18 Dec 2005 19:58 GMT
> You cannot assume that it is going to make sense to do a bitwise clone
> of subclass fields. So in general, subclasses will need to override the
> copy method, even if Cloneable is implemented.

Yes, that's true.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Roedy Green - 19 Dec 2005 01:23 GMT
>Then again, using Object.clone() is the only reasonable way to get
>correct object copying behavior in a non-final class with accessible
>(protected or public) constructors.  That's the fundamental reason to
>use clone() instead of a copy constructor anyway... so yes, I'd say that
>implementing Cloneable is fairly important.

clone won't let you promote or demote an object (add remove fields
moving down/up the hierarchy). It just gives you a copy of that you
already have.

e.g. Dog -> Dalmatian  Dalmatian -> Dog
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 14 Dec 2005 23:53 GMT
>Could you elaborate why copy constructor is so common and important in
>C++ while in java it is not so important? Thank you very much.

There is no easy way to code them in Java which discourages their use.
I have many times asked for efficient ways to promote and demote
objects.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Chris Smith - 18 Dec 2005 18:58 GMT
> In java, what is returned is actually a reference, not exactly the memory
> address - but you can see it that way, it can make it easier to understand if
> you come from C++

I don't understand what you mean here, zero.  Chances are extremely good
that the reference IS exactly the memory address.  The relationship
between the words "reference" and "memory address" is not that they are
alternatives to each other, but that a reference is an abstraction
that's very likely (almost certain, in fact) to be implemented as a
memory address.

So depending on whether you're talking within or outside the language
model, it is reasonable to say either that a method returns a reference
or a memory address, and it's almost certainly correct (though not
guaranteed as such by any spec) to say that a reference is a memory
address.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Stefan Ram - 18 Dec 2005 19:15 GMT
>Chances are extremely good that the reference IS exactly the
>memory address.

 From the point of view of the JLS3, a "reference" is a term of
 the specification of the language Java, while a "memory
 address" is not. So the meaning of "reference" is specified,
 while the meaning of "memory address" is not.

 (JLS3 mentions "address" twice in 17.5.1, but this only
 applies to the semantics of final fields.)
Chris Smith - 18 Dec 2005 19:20 GMT
>   From the point of view of the JLS3, a "reference" is a term of
>   the specification of the language Java, while a "memory
[quoted text clipped - 3 lines]
>   (JLS3 mentions "address" twice in 17.5.1, but this only
>   applies to the semantics of final fields.)

Yes.  Sort of like what I said in the very next paragraph, which you
snipped.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Roedy Green - 19 Dec 2005 01:24 GMT
>  Chances are extremely good
>that the reference IS exactly the memory address.

In the early JVM a reference was a handle, the address of an
addresses. That was how the JVM planned to move objects around without
having to find and patch all the references to them.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Chris Smith - 19 Dec 2005 04:28 GMT
> In the early JVM a reference was a handle, the address of an
> addresses. That was how the JVM planned to move objects around without
> having to find and patch all the references to them.

Yep, and as of the next generation JVM (HotSpot-based) and Java 1.2,
that is no longer the case.  I am not aware of any commonly used VMs
(possibly excpting the Microsoft VM, if that's still commonly used) for
which the indirect handle technique is still used.  However, I'm not
familiar with KVM... perhaps it's used there?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

zero - 19 Dec 2005 18:33 GMT
>> In java, what is returned is actually a reference, not exactly the
>> memory address - but you can see it that way, it can make it easier
[quoted text clipped - 12 lines]
> (though not guaranteed as such by any spec) to say that a reference is
> a memory address.

In C++ a pointer is a memory address, no discussion about that.  However in
Java, like you said, a reference is not defined as being a memory address,
and could be implemented very differently in any VM.  It is entirely
possible that it is indeed implemented as a direct memory location, but
saying that a java reference is a memory address does not hold true -
unless you're talking about a specific VM of which you know it to be true.
That's what I meant.

Signature

Beware the False Authority Syndrome

Stefan Ram - 19 Dec 2005 18:59 GMT
>In C++ a pointer is a memory address, no discussion about that.

 Then, why does the following programm print

true false

 ?

#include <iostream>
#include <ostream>
#include <iomanip>

class A { int a; }; class B { int b; };
class C : public A, public B {};

int main()
{ C * c = new C; B * b = c;
 ::std::cout << ::std::boolalpha <<
 ( b == c )<< ' ' << (( void * )b ==( void * )c ) << '\n'; }
Chris Smith - 19 Dec 2005 21:13 GMT
> In C++ a pointer is a memory address, no discussion about that.  However in
> Java, like you said, a reference is not defined as being a memory address,
> and could be implemented very differently in any VM.

I'd say that a C++ pointer is to a memory address as a Java reference is
to a memory address.  That is, the concepts are the same.  The only
significant difference is that in C++, there have never been too awfully
many significant implementations for which it's not true.  In Java, such
implementations have existed in the past, but not so much any more
(unless it's true of KVM, which I don't know for sure).

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Roedy Green - 19 Dec 2005 22:36 GMT
>I'd say that a C++ pointer is to a memory address as a Java reference is
>to a memory address.  That is, the concepts are the same.

Back in the olden days, hardware relocation was a big selling feature
of the Univac 1100.  Each program had its own address space logically
starting at 0.  In the IBM 360, there was one big flat space and each
program had to relocate itself. Windows 3.1 also used a shared address
space.

In a machine without hardware relocation you might use a program
relative pointer to provide software relocation. It would have to be
added to a base pointer at the last minute.  Such a beast would be
considered a pointer, but not a memory address.

Another example would have been the Intel 8086.  It had a segmented
address space.  segment and offset.  You addressed a segment and 64k
offset within that segment.  You might use program relative flat
32-bit pointers that were converted to seg:offset at the last second,
as Ray Duncan did in his Forth interpreter.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

zero - 21 Dec 2005 12:52 GMT
>> In C++ a pointer is a memory address, no discussion about that.
>> However in Java, like you said, a reference is not defined as being a
[quoted text clipped - 6 lines]
> Java, such implementations have existed in the past, but not so much
> any more (unless it's true of KVM, which I don't know for sure).

ok I guess there is discussion about that then :-)  I stand corrected.

Signature

Beware the False Authority Syndrome



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.