Java & native memory access
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mark_lassche
Posted On:   Saturday, April 7, 2001 01:14 PM

I would like to access memory allocated in the native code by java. More specifically; I have a (int) pointer to the video memory and would like to write to it from java directly. I would like to avoid having to copy all the ints in the pointer to a java int array. Is it possible to just pass the native int pointer back to Java ? The code should look something like this: JAVA part public native int[] getVideoMemory(); public void someMethod() { for (int i = 0; i < 100; i++){ getVideoMemory[i] = 99; } native part JNIEXPORT jintArray JNICALL Java_jni_JNIDemo_d   More>>

I would like to access memory allocated in the native code by java. More specifically; I have a (int) pointer to the video memory and would like to write to it from java directly.

I would like to avoid having to copy all the ints in the pointer to a java int array. Is it possible to just pass the native int pointer back to Java ?

The code should look something like this:


JAVA part

public native int[] getVideoMemory();



public void someMethod() {

for (int i = 0; i < 100; i++){

getVideoMemory[i] = 99;

}


native part



JNIEXPORT jintArray JNICALL

Java_jni_JNIDemo_doArray

(JNIEnv *env, jobject object)


int* videoMemoryPointer = grabVidMem();


// do some "magical" stuff here


return // the newly magical jintArray;

   <<Less

Re: Java &amp; native memory access

Posted By:   Alexander_Krapf  
Posted On:   Thursday, April 12, 2001 01:26 PM

Hi Mark,


You have two conflicting requirements. It seems that the JVM and the video card should want to own the memory in question. This is not possible using today's JNI. If you could instruct the video card to use a certain memory range which can be owned by the JVM, then you could conceivably succeed without a copy by using GetPrimitiveArrayCritical() and ReleasePrimitiveArrayCritical(), but it depends on your JVM and on whether the restrictions for the use of this API can be met. I quote:


"It is important to treat the code inside this pair of functions as running in a critical region. Inside a critical region, native code must not call other JNI functions, nor may the native code make any system call that may cause the current thread to block and wait for another thread in the virtual machine."


I think you're out of luck.


Alex

About | Sitemap | Contact