• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

References to Variables in Memory

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a reference is made to a variable stored in memory and is grabbed for use, does the JVM make a copy of that variable to manipulate, or does it grab the original and manipulate that? And if it does grab the original, how does the JVM keep track of that in memory?

------------------
Happy Coding,
Gregg Bolinger
 
vicky bawge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
The JVM does manipulate the original and it doesnt care how many other references are pointing to it. once it manipulates the original, all the references, as they are just pointing to the original stuff get updated automatically.
Its like your ten relatives have your house address and you paint your house with different color. Dont you think, If all of them follow the address (reference) and visit your home, should see the new paint on your house.
Does that answer your question,
-Vivek
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does for half of my question. But how do the "relatives" know where it is in memory? Is it pointers? And if so, does anyone know why JAVA does not allow the use of pointers in programming?
------------------
Happy Coding,
Gregg Bolinger
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ClassLoader manages each class tracks all object references in its space. This tracking is done by way of a hashcode which could arguably represent a memory address.
But an object reference doesn't directly access the process map; the JVM does that. The JVM does not expose that map to its classes.
You really really really want a pointer, don't you?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL, I just don't like the fact that I can't manager MY memory. I know that JAVA has done a good job with the garbage collector but I still like a little more control.
Thanks for everybodies replies.

------------------
Happy Coding,
Gregg Bolinger
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
LOL, I just don't like the fact that I can't manager MY memory. I know that JAVA has done a good job with the garbage collector but I still like a little more control.

In a far off kingdom long ago, all the peasants complained about having to drag their trash out to the dump. It was too time consuming. It was labor intensive. It wasted time they should have spent building better houses, and distributed systems (these were very advanced peasants). So the king, a wise man, arranged for community trash removal, paid for by a small increase in taxes. There was much rejoicing.
Then the peasants complained they wanted their trash back. For you see, they were used to realizing they accidentally threw something out, like a child's retainer, or linked list, and could go back to the dump to take it out. But now that someone else remvoed their trash, they didn't know where it was put in the dump, and couldn't find it again.
So the king asked his knights of the hash table for advice, and they created a public relations office for the dump. This would keep track, reference if you will of where the garbage was placed in the dump. Of course, the dump would often recycle the garbage and not let the public relations office know, so it wasn't quite perfect. Some said this system was weak; the kings detractors called him soft on garbage removal. but more people were happy.
The system is pretty complex now. Further improvements in the system won't be easy. If there are to be any, they are likely to come from the king's wizard, Merlin. So you'll have to check Merlin's web site for more info.
The end.

--Mark
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neat story. And now forgive me for being ignorant, but Merlin is java.sun.com??
And could someone show me a link for the information that Mark suggested? And maybe with a little less drama?
Thanks

------------------
Happy Coding,
Gregg Bolinger
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL - I love it !
Merlin is the jdk1.4 that is now in beta release. http://java.sun.com/features/2001/06/golden.j2se.html
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Cindy.

------------------
Happy Coding,
Gregg Bolinger
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a new API Doc available for download for the 1.4 additions?
Can't seem to find one if there is.
Thanks for any help.
Never Mind, I found it on-line. Thanks though
------------------
Happy Coding,
Gregg Bolinger
[This message has been edited by Gregg Bolinger (edited October 17, 2001).]
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "Public Relations" office was a veiled reference (maybe I should say, weak reference :-), to the java.lang.ref classes. See the standard API docs for them.
Also read http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/index.html

--Mark
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you don't mean Phantom reference? <rimshot>
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
vicky bawge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course JAVA HAS POINTERS.
but they are very very restricted.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vicky bawge:
Of course JAVA HAS POINTERS.
but they are very very restricted.

Could you explain?

------------------
Happy Coding,
Gregg Bolinger
 
vicky bawge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
All you need to know about the ugly pointer is here http://cslibrary.stanford.edu/106/
I am calling it ugly because it somewhat takes us back to the old days of assembly language where the programmer had to deal with the hardware intricacies like memory layout, cpu code instructions etc. I agree its not that bad but its one thing that doesn't allow us to abstract away from the computing machine.
Thanks,
-Vivek
 
vicky bawge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is a pointer (reference) in java including the basic data types.
e.g even you can call getClass() for int.
Any objections.
-Vivek
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic