• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a maximum size for ByteBuffers in JNI?  RSS feed

Steven Rombauts
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java Ranchers,

I am currently trying to learn my way around the JNI api, and my first experiences were very pleasant :-)
What I am doing is wrapping a given .LIB file, out of which I call the function processBuffers.
Everything is working great, as long as the ByteBuffers, which hold float values, (or primitive arrays, I tried them both) that I pass into this function, are equal or smaller than 2048*4. The entire program works great, I get the desired results and performance is also great.
But when I pass a bigger buffer, I get an EXCEPTION_ACCESS_VIOLATION and a JVM crash.

I googled around and came across some forum posts here and there which would take about increasing the stack size. But I don't really need such huge arrays anyway, but since this is for audio signals, a bit more flexibility could come in handy. And if I were to be running out of stack space, I think I should get a stack overflow error instead of an access_violation?

I spoke with the author of the .lib file, and he guarantees that this should not happen. (the crash happens at the time of that processBuffer() method).

I tried looping over the buffer and printing out the values with printf() before calling the method in the lib file, and this gave no errors.
My c++ code looks like this;

There is not much happening on the Java side, I get the ByteBuffer object by calling the native method allocateByteBuffer(int size), I put the values in and then call the method which does the ProcessBuffer() part.

Everything works great, just not with bigger sized buffers. And since I am not really a C++ expert, I am kind of lost as to where to continue looking for the cause of this problem. Does anyone here might have any tips? Is this a Java problem or a C problem or both? :-)

Thank you in advance,
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!