>> I need to convert an Object reference to an integer. How to do it?
>
> Now I know System.identityHashCode(object) can give me an
> unique integer.
> >> I need to convert an Object reference to an integer. How to do it?
>
[quoted text clipped - 29 lines]
> Regards,
> John
It is a requirement by JNI.
I package object values to a byte buffer. As we know, C++ has address
and can convert to an integer.
I cannot package Object reference to a byte buffer, so I need convert
it to an unique integer. To illustrate it,
see below.
|-----------------------|
| Type |
------------------------
| Length |
------------------------
| Address |
-------------------------
JNI takes the third element as an address, i.e. an unique integer, I
hope to package the Java object reference.
Because the object reference is like an address. But Java does not
permit converting a reference to an integer.
jmaline@gmail.com - 07 Feb 2007 02:22 GMT
> It is a requirement by JNI.
> I package object values to a byte buffer. As we know, C++ has address
[quoted text clipped - 15 lines]
> Because the object reference is like an address. But Java does not
> permit converting a reference to an integer.
Holy cow, you're talking JNI, not just Java. That's a completely
different thing! You're not getting much help because you're not
asking your question very well.
How about starting over. Something like... "I want to use JNI
function X() to accomplish Y. I'm having trouble understanding how
to format the data for parameter Z." Fill in those blanks and a bit
of explanation and you've got a much better chance of getting help.
Better still, go to http://www.google.com/codesearch and type in the
JNI function you're trying to use. You'll probably come up with 100
examples of code using it. Browse a few examples and you might find
one that helps you out.
I'm afraid my JNI is rusty enough that I probably won't be any more
help.
Good luck,
John
Esmond Pitt - 07 Feb 2007 02:59 GMT
> It is a requirement by JNI.
> I package object values to a byte buffer. As we know, C++ has address
[quoted text clipped - 15 lines]
> Because the object reference is like an address. But Java does not
> permit converting a reference to an integer.
No but C does. Pass the reference to the JNI function *as a reference*
(i.e. a jobject?), then convert it to int or long in there. You also
have to do something to lock the address while you're using it but it's
nearly ten years since I did this and I can't remember the details.
Jeff Higgins - 07 Feb 2007 03:05 GMT
It is a requirement by JNI.
I package object values to a byte buffer. As we know, C++ has address
and can convert to an integer.
I cannot package Object reference to a byte buffer, so I need convert
it to an unique integer. To illustrate it,
see below.
|-----------------------|
| Type |
------------------------
| Length |
------------------------
| Address |
-------------------------
JNI takes the third element as an address, i.e. an unique integer, I
hope to package the Java object reference.
Because the object reference is like an address. But Java does not
permit converting a reference to an integer.
[http://www.javolution.org/api/javolution/io/Struct.html]