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

W

ws_dev2001

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
 
J

Jarmo

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.
 
J

Jack Klein

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.
 
L

Lawrence Kirby

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
 

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,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top