1

I am transferring byte buffer data from the C++ function to java method trough the JNI.

As I read in one article(Shared Memory between two JVMs). mappedByteBuffer allows to read the data from memory, but it will load the file into memory. I don't want to use file because byte buffer get filled in C++ from remote source, if I use file it will overhead the file reading and writing calls and degrades the performance, so eliminating the MappedByteBuffer

My use case: Is there any mechanism in java to read the byte array at the particular offset? How to share the memory between c++ function and java method in same process? or Do we have any mechanism to assign specified offset to the byte array variable in java

Thanks in advance...

  • 1
    Possible duplicate of [Shared memory between C++](https://stackoverflow.com/questions/15414753/shared-memory-between-c-and-java-processes) – Arno C Jan 03 '18 at 14:30
  • and [this one](https://stackoverflow.com/questions/26790224/how-do-i-fetch-specific-bytes-from-a-file-knowing-the-offset-and-length). I find the phrasing of your question rather abstract, so correct me if I'm wrong. – Arno C Jan 03 '18 at 14:31
  • Thanks Arno C, my intention is to share the byte array in the memory, I don't want to load file as I am getting byte array from the remote source. writing byte array into file in c++ reading it in java makes overhead. So I am not preferring to load a file into memory – vagdevi pedalenka Jan 03 '18 at 14:48
  • I think you underestimate the file cache. "Writing" a file can be very cheap. – MSalters Jan 03 '18 at 19:37

0 Answers0