Monday, July 27, 2009

How to reference memory locations using JAVA similar to pointers in c or c++?

I need to identify which memory location a variable is stored - using java codes.

How to reference memory locations using JAVA similar to pointers in c or c++?
As mentioned by gtopala, you cannot get the memory location of an object in JVM. Why would you want it anyway? For debugging purpose you can probably make use of Object.hashCode()


There is no meaningful concept of the address of a variable in the Java language.





--


Ck


http://www.gfour.net
Reply:I am afraid thats quite not possible. You can use JNI, to call C++ code in your java programs, yet I am not sure if its possible to get the objects memory location as Java objects live in JVM heap and not in OS controlled Memory area. Report It

Reply:You can't get the real address in Java. You can get a relative location inside JVM.


No comments:

Post a Comment