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 / October 2006

Tip: Looking for answers? Try searching our database.

JNI allocate array of arrays of primitive

Thread view: 
Bill Medland - 25 Oct 2006 23:21 GMT
How, in JNI, can I allocate an array of arrays of primitives?

The problem I am having is in finding a suitable class pointer to pass to
NewObjectArray.

I can use java/lang/Object but I was wondering if I could get slightly
closer to [java/lang/byte.

TIA

Signature

Bill Medland

Jean-Francois Briere - 26 Oct 2006 04:28 GMT
/**
* Creates a Java byte[][] object from a C++ char[len1][len2] multidim
array.
*/
jobjectArray create_array_of_byte_array(JNIEnv * env, char *
c_2d_char_arr, int len1, int len2) {
   jclass byteArrCls = env->FindClass("[B");
   jobjectArray arrOfByteArrObj = env->NewObjectArray(len1,
byteArrCls, NULL);
   for (int i = 0; i < len1; i++) {
       jbyteArray byteArrObj = env->NewByteArray(len2);
       env->SetByteArrayRegion(byteArrObj, 0, len2, (jbyte
*)&(c_2d_char_arr[i * len2]));
       env->SetObjectArrayElement(arrOfByteArrObj, i, byteArrObj);
   }
   return arrOfByteArrObj;
}


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



©2008 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.