Posted By:
Ganesh_Iyer
Posted On:
Thursday, December 4, 2003 09:58 AM
u can pass objects to native code. And then use jni reflection calls to access the data in the object passed. This is the cleanest way, but more complicated and less efficient.
Alternatively, u could use java nio direct buffers to implement a shared memory model. in this model java nd native code operate on same memory addresses.
ie. if u use a shared java.nio..ByteBuffer the java refernce to the bytebuffer object will correspond to a pointer on the native side.
eg:- if u perform a putInt(120) on the ByteBuffer object, the native memory at that address will alo be updated.
u could simply typecast the shared memory on the native side into a struct to access the values passed in directly.
u would of course need to build a simple serializing framework to accomodate the same, but its probably worth it.
Another advantage of doing it this way is that there is absolutly no extra memory copy between java and native layer.