NewDirectByteBuffer() & java.nio.ByteBuffer

Hi All,

I'm developing an application which uses the JNI interface to embed the

JVM to a C application. So my problem is, I would like to "map" some C struct

in the Java VM and that isn't a problem currently since I use the NewDirectByteBuffer()

JNI call to allocate a ByteBuffer for a given address.

My problem cames whenever I need to change the address for the mapped

objects in the Java VM because, for some reasons, the pointer has been changed in the C heap.

So instead to allocate yet another DirectByteBuffer I

would like to change only the address and nothing else. Furthermore the

object address in the C heap may change hundres of times per seconds,

so allocating and destroying ByteBuffers at this rate wouldn't be really nice.

Does anyone have some tips to suggest?

Thanks in advance.

[882 byte] By [robyfFa] at [2007-11-26 15:28:05]
# 1

I'll reply my self,

seems that if I change the ByteBuffer protected field 'address' using the

JNI (*env)->SetLongField() in the given object instance, I'm getting what I

want :-)! I'm able to change the base address of a ByteBuffer!

So now the question is if I will go in "trouble" changing such protected

field? The ByteBuffer caches such address for some internal reasons or the

address field is used for all the ByteBuffer computations always using such

field?

Thanks in advance.

robyfFa at 2007-7-8 21:44:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...