Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

JNIEnv *

Thread view: 
DGG - 22 May 2007 15:56 GMT
I am reading the JNI spec. One feature puzzles me. There is this
universial JNIEnv *env pointer in every function. However, if it is C,
you use (*env)->xxxx to access the fields in the environment; if it is
in C++, you use env->xxxx to access it.

Does anybody know what's the rationale behind such a design?

Thanks
Gordon Beaton - 22 May 2007 17:54 GMT
> I am reading the JNI spec. One feature puzzles me. There is this
> universial JNIEnv *env pointer in every function. However, if it is
> C, you use (*env)->xxxx to access the fields in the environment; if
> it is in C++, you use env->xxxx to access it.
>
> Does anybody know what's the rationale behind such a design?

In both cases, you are invoking member functions on the JNIEnv object.
In C, you need to explicitly pass the "this" reference to each method.
In C++ the result is exactly the same code, but the compiler removes
the extra level of indirection and inlines the first argument for you.

/gordon

--
Thomas Fritsch - 23 May 2007 12:52 GMT
> I am reading the JNI spec. One feature puzzles me. There is this
> universial JNIEnv *env pointer in every function. However, if it is C,
> you use (*env)->xxxx to access the fields in the environment; if it is
> in C++, you use env->xxxx to access it.
>
> Does anybody know what's the rationale behind such a design?
As far as I understand the JNI spec (see
<http://java.sun.com/docs/books/jni/html/other.html#30951> ),
the rationale behind that is to make it simpler for the programmer.
But unfortunately they can offer this simplification only for C++
language, but not for C language.

BTW: Because of the above I prefer to do JNI-programming in C++.

Signature

Thomas



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.