jni, native methods and access to shared memory

Discussion in 'Java' started by freepee, Jul 2, 2011.

  1. freepee

    freepee

    Joined:
    Jul 2, 2011
    Messages:
    1
    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?
     
    freepee, Jul 2, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Fallon
    Replies:
    3
    Views:
    788
    =?Utf-8?B?Z3V5?=
    Jul 16, 2004
  2. bigbinc

    Java, jni.h and native method

    bigbinc, Oct 10, 2003, in forum: Java
    Replies:
    1
    Views:
    1,282
    Gordon Beaton
    Oct 10, 2003
  3. jin zhang
    Replies:
    1
    Views:
    1,309
    Chris Uppal
    Oct 2, 2004
  4. ws_dev2001@yahoo.com

    Riding JNI[Java Native Interface]: Java to C and back

    ws_dev2001@yahoo.com, Feb 27, 2005, in forum: C Programming
    Replies:
    3
    Views:
    418
    Lawrence Kirby
    Feb 28, 2005
  5. bgabrhelik
    Replies:
    0
    Views:
    895
    bgabrhelik
    Sep 29, 2009
Loading...

Share This Page