pass pointer to java with NDK on Android
i want to use memset
in a Android program.
i try NDK to code in C then use library in my JAVA Android's program.
input of memset
is *ptr
.i want to send a Memory Address (like 0x8134
) to program and then use memset
to change i开发者_Go百科t.how could i send this to my program?
First, as you know, Java does not have the concept of pointers and thus cannot really allocate/use a memory area using pointers(on which memset needs to be used).
That said, it is possible to use ByteBuffer.allocateDirect
to get a direct byte buffer whose address can be used on the native side of JNI to do direct memory operations. Further, you can directly allocate memory in the native code and pass it back to the Java code as a ByteBuffer. This is the closest you can get to C/C++ type memory access/manipulation.
More details:
http://onjava.com/pub/a/onjava/2002/10/02/javanio.html?page=2
http://docs.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html
精彩评论