Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Riding JNI[Java Native Interface]: Java to C and back

Reply
Thread Tools

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

 
 
ws_dev2001@yahoo.com
Guest
Posts: n/a
 
      02-27-2005
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

 
Reply With Quote
 
 
 
 
Jarmo
Guest
Posts: n/a
 
      02-27-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      02-28-2005
On 27 Feb 2005 10:50:21 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
Lawrence Kirby
Guest
Posts: n/a
 
      02-28-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link style over riding another Ian Davies HTML 5 04-25-2006 07:09 AM
DVD Verdict reviews: PRIMER, RIDING THE BULLET, THE YES MEN, and more! DVD Verdict DVD Video 0 04-19-2005 08:12 AM
DVD Verdict reviews: THE RANCH, ROSELAND, RIDING HIGH (1950), and more! DVD Verdict DVD Video 0 02-04-2005 10:12 AM
Re: Over-riding equals method dilemma Michael Borgwardt Java 23 08-23-2004 12:44 PM
Horse Riding myrt webb MCSE 10 09-22-2003 10:25 PM



Advertisments