Can I use ByteArray and NonDirect ByteBuffer with JNR #162
Replies: 1 comment 5 replies
-
Hello there!
For non-direct (allocated on heap with If it is direct (allocate in native memory with I don't know what With proper use of these buffers on the native side (i.e. within bounds) they will not cause a segfault, but of course once you're in native territory then bad code can certainly trigger faults by walking off the end of an array. There's other quirks like the lifetime of the native side (non-direct shouldn't be saved after the call, direct will remain the same pointer until GCed, etc) but hopefully this answers your general question! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
This might be a noob question. Can I use ByteArrays and ByteBuffers that are not allocateDirect with JNR?
Something like:
Java code
C code
As far as I am aware, if I do
ByteBuffer.allocate(size)
the underlying memory resides in the heap and can be moved around during GC compactation.Could this lead to a segfault when using the memory in C? Does JNR protect against this?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions