JNI: passing massive int array to C++
807580May 22 2009 — edited Sep 23 2009HI,
I would like to pass a huge array of primitive integers (int[]) to native C++ code. I've read that a direct pointer to such an array cannot be guaranteed by the JVM and the content might be copied instead. Now, the time it requires to copy the entire array is not my primary concern (although it would be nice to avoid that). My problem is rather that my Java int[] array can be as large as 800mio(!) integers and perhaps more (FYI, I have already 'compressed' (i.e. optimized) the actual information to the minimal amount of necessary bits only, so that I don't waste unnecessary space). I don't know exactly, how JVM represents 800 million integers in memory, but that is AT LEAST 3.2GB of memory (if 1 int = 32bit) right there. Anyway, is there a memory efficient way to pass such a data set without having to copy it to another memory location for native access in C++? A brief code example for Java and C++ would be great.
Thanks so much,
Dan