By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<ws********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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.
Nov 14 '05 #2

P: n/a
On 27 Feb 2005 10:50:21 -0800, ws********@yahoo.com 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/~a...FAQ-acllc.html
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.