|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

09-10-2008, 11:20 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 7
|
|
|
A variable pointer
Hi,
could you please advise me how can I get a variable pointer (address) to see where it points to?
Thanks a lot,
T.
|
|

09-10-2008, 01:31 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
|
|
|
It's not possible in Java, and it's foolish think to try. There is no point to deal with variable address in Java.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

09-10-2008, 03:54 PM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 7
|
|
|
Yes, I see. I just wanted to use that to check e.g. whether two different variables pointed to the same or different memory spot.
Thank you Eranga.
T.
|
|

09-10-2008, 04:45 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
whether two different variables pointed to the same
Use the == operator with the two variables
|
|

09-11-2008, 05:44 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
|
|
Originally Posted by tapies
Yes, I see. I just wanted to use that to check e.g. whether two different variables pointed to the same or different memory spot.
Thank you Eranga.
T.
You mean pointed to the same memory address? Say you have two int variables as follows,
So you want to know that bot i and j use the same memory address, right?
The answer is no. Whenever the new variable is declared it allocated a memory space as well as address.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

09-11-2008, 06:42 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 475
|
|
Originally Posted by Eranga
It's not possible in Java, and it's foolish think to try. There is no point to deal with variable address in Java.
More, Java was carefully designed so you could not do this. It was a bug farm in C, and the Java designers did not want to maintain the bugs.
While you can do things like use == and .equals() to get an idea, none of them are guaranteed to give you the information. Its a secret and supposed to stay that way.
|
|

09-11-2008, 06:46 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 4
|
|
|
If you wanted a pointer like variable manipulation. You can created a class that makes and stores variables in a table and then you can "address" then use an index acting as an address. Lol, just trying to make a useful reply.
|
|

09-11-2008, 08:16 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
|
|
|
However my thoughts on this is, very bad idea. Dealing with the memory address in Java is not required in any way, link in C/C++
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

09-11-2008, 09:33 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 475
|
|
Originally Posted by ChazZeromus
If you wanted a pointer like variable manipulation. You can created a class that makes and stores variables in a table and then you can "address" then use an index acting as an address. Lol, just trying to make a useful reply.
Your reply is technically correct, but a really bad idea. This is not the Java Way. If you want to write low level code, just use C.
I would argue with your claim that it is a useful reply.
|
|

09-11-2008, 10:24 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 7
|
|
|
I see, that is not the Java Way.
Thanks a lot to all of you.
F.
|
|

09-11-2008, 02:55 PM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 4
|
|
*Shrug*
Yeah, well it's the closest thing to addresses I could think of 
|
|

09-12-2008, 11:33 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
|
|
Originally Posted by ChazZeromus
*Shrug*
Yeah, well it's the closest thing to addresses I could think of 
The way you are talking is correct as fishtoprecords says in his last post. And also he said that it's a bad idea. In simple word the reason is, Java is a high level language, so we never worried about in memory management.
Say you have define an array as follows in C++ and Java
int[] temp = new int[12];
Then you are using it and do some processing. After that what are you doing? In Java, nothing. But in C++, you have to clear the memory, simply delete the array.
I hope you are much clever than me on C++. If so I no need to talk about what happen if I forget to delete the array.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

09-12-2008, 11:55 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 475
|
|
Originally Posted by Eranga
what happen if I forget to delete the array.
What happens is, of course, that you get a nearly impossible to find memory leak. And you not only have to remember to write the code to do the delete, but you have to make sure that its executed on every path in your code, including any and all exceptions.
Don't forget to trap all exceptions that you never heard of, because some other developer changed code way down in the call tree in ways you never expected.
There are real engineering reasons why Java has garbage collection: it makes the computer do what programmers and other humans do poorly.
Back in the mid-1990s, folks had theological arguments that garbage collection was too slow. And it can be too slow for realtime work. So the solution is to not use Java for real time work.
The theological arguments ignored the cost and slowness of finding memory leaks in complex systems.
|
|

09-12-2008, 12:44 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
|
|
|
Thanks for the info. Actually I'm not at good in C++. Just learning in my free time.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|