jni, native methods and access to shared memory
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   free_pee
Posted On:   Saturday, July 2, 2011 04:30 AM

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   More>>

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?

   <<Less
About | Sitemap | Contact