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

Discussion in 'C Programming' started by ws_dev2001@yahoo.com, Feb 27, 2005.

  1. Guest

    Hello all,
    I am trying to obtain the size of a java object in C by using JNI. As
    we do not have a proper implementation of this in java[other than obj
    serialization and reflection etc...], I decided to see if C could
    provide me some accurate data.
    As in java, C does provide accurate sizeof for primtives and can even
    handle String objects received from java. In java reflection, we cannot
    find/estimate the length of the string with as much ease as it is in C
    via JNI.
    Sizeof impl in C seem to be centred around primitives and structs
    etc...
    So, how do I find the sizeof a java object being sent via native method
    call to a C program? Do I need to allocate memory for this object
    [estimation based]?
    I tried loading the jobject into a struct but sizeof always gives me 4
    whether it is via sizeof(jobject) or sizeof(struct myjostruct)!!!
    I understand that this is the size allocated for the address in memory.
    Can anyone please help ?
    TIA
     
    , Feb 27, 2005
    #1
    1. Advertising

  2. Jarmo Guest

    <> wrote in message
    news:...
    > Hello all,
    > I am trying to obtain the size of a java object in C by using JNI.


    I think you should be looking for a design where it's not necessary to
    determine the size of a Java object.
     
    Jarmo, Feb 27, 2005
    #2
    1. Advertising

  3. Jack Klein Guest

    On 27 Feb 2005 10:50:21 -0800, wrote in
    comp.lang.c:

    > Hello all,
    > I am trying to obtain the size of a java object in C by using JNI. As
    > we do not have a proper implementation of this in java[other than obj
    > serialization and reflection etc...], I decided to see if C could
    > provide me some accurate data.


    Nope, we can't. As far as the C standard, and therefore this group is
    concerned, C is the only language in existence. There is no such
    thing as Java, C++, BASIC, FORTRAN, etc.

    Even "using JNI" is done by a non-standard extension provided by your
    operating system/compiler combination.

    You need to ask in a Java group, or maybe one for your particular
    compiler/OS combination.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Feb 28, 2005
    #3
  4. On Sun, 27 Feb 2005 10:50:21 -0800, ws_dev2001 wrote:

    > Hello all,
    > I am trying to obtain the size of a java object in C by using JNI. As
    > we do not have a proper implementation of this in java[other than obj
    > serialization and reflection etc...], I decided to see if C could
    > provide me some accurate data.
    > As in java, C does provide accurate sizeof for primtives and can even
    > handle String objects received from java. In java reflection, we cannot
    > find/estimate the length of the string with as much ease as it is in C
    > via JNI.


    All sizeof does in C is tell you the size of C's types, or specifically
    the size (in byte/character unit) as used by that particular
    implementation.

    > Sizeof impl in C seem to be centred around primitives and structs etc...
    > So, how do I find the sizeof a java object being sent via native method
    > call to a C program? Do I need to allocate memory for this object
    > [estimation based]?


    C knows nothing about Java and in general doesn't provide runtime
    information about object sizes (noting C99 VLAs).

    > I tried loading the jobject into a struct but sizeof always gives me 4
    > whether it is via sizeof(jobject) or sizeof(struct myjostruct)!!! I
    > understand that this is the size allocated for the address in memory.
    > Can anyone please help ?


    If what you want is possible it will be via a mechanism provided by
    Java/JNI. A good place to ask about it would be a Java related newsgroup.

    Lawrence
     
    Lawrence Kirby, Feb 28, 2005
    #4
    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. bigbinc

    Java, jni.h and native method

    bigbinc, Oct 10, 2003, in forum: Java
    Replies:
    1
    Views:
    1,281
    Gordon Beaton
    Oct 10, 2003
  2. Michael Borgwardt

    Re: Over-riding equals method dilemma

    Michael Borgwardt, Aug 14, 2004, in forum: Java
    Replies:
    23
    Views:
    750
    Chris Uppal
    Aug 23, 2004
  3. jin zhang
    Replies:
    1
    Views:
    1,307
    Chris Uppal
    Oct 2, 2004
  4. Replies:
    13
    Views:
    6,183
  5. bgabrhelik
    Replies:
    0
    Views:
    894
    bgabrhelik
    Sep 29, 2009
Loading...

Share This Page