jni, native methods and access to shared memory

Joined
Jul 2, 2011
Messages
1
Reaction score
0
hi,
i have a c library that manages shared memory and other stuff... i can't modify it but i want to use it from java (i want to create a thing similar to a wrapper). i'm using jni, and i have a class buffer with an attribute byte[] that should always be a "copy" of the content of the buffer. my opinion is that is unsafe to have an object copy of the buffer because the buffer can be modified (accidentally) by other processes and so the buffer wouldn't be exactly like the java object. Moreover it implies that when i recognize that the buffer changed, i have to update the java object (it can be hard). finally copying the buffer into an object means double the memory usage.
my idea was to store in the java object only an id of the buffer, and then get info through get methods that call c native methods each time (i know it's expensive, but i prefer slow things that work)
do you think i must have a java object storing all the content of the buffer or it's better to have a java object that stores only an id of the buffer?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top