In thinking about calling java objects how does one prevent java from changing the location of the object? In C++ one asks the JVM for a reference to an object an then you typecast it to a pointer. So the problem is obvious, your pointer is no longer valid. Any idea's?
In looking at the answers thus far let me clarify. As I understand it, when java creates an object it provides a reference ( an equivalent to a pointer ) and that reference leads all other objects to its actual data and methods. When calling java from within C++ you have to type cast the reference to a pointer and thus you have the location, in memory, of the object.
Java maintains its memory pools as cleanly as possible to optimize execution / heap fragmentation, etc. In doing so it may very well move objects to different memory pools, thus changing the actual memory address the reference points to ( internally, in the jvm ) and updates the reference list, so that all the other java objects can still access the same objects correctly.
My question comes to the point when in C++, since their is no contract between the C++ runtime and the JVM, you cast the reference to a pointer that now points to a physical address in memory. If the JVM relocates the object in the process of optimization, would that pointer in C++ now be invalid in a long running java program?
I hope this helps clarify the question.