I have a native method which calls a Java function to create a bitmap, then returns the bitmap data as array of int.
The method isn't very efficient, because I need to create a Bitmap, then an IntBuffer to copy the bitmap data, then the native method creates a new int array to store the data. The IntBuffer is then recycled (the Bitmap object could be reused), and when I create more than 10 bitmaps, the garbage collector starts slowing down the application.
Can I just create the int array in JNI, wrap it into a jintarray and use it directly in Java?
Found a solution.
I can wrap a native int* (or char*) into a ByteBuffer using the JNI function NewDirectByteBuffer. Then use it as a parameter, instead of the jintarray.