This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: CNI byte array


On Fri, Mar 02, 2001 at 12:27:54AM +0100, Rolf W. Rasmussen wrote:
> On Thu, Mar 01, 2001 at 02:23:03PM -0600, Shu-Fang Chen wrote:
> >[...] 
> > I am working on a project using Cygnus Native Interface. I would like to
> > send a message (which is a byte array) from C back to Java. Then, I need to
> > create a object of JArrayByte (jbyteArray CNI_ArrayPtr =
> > JvNewByteArray(ArrayLength);) and copy the content in the C byte array to
> > the JArrayByte object (memcpy(elements(CNI_ArrayPtr), C_ArrayPtr,
> > ArrayLength);).  It would take much more time and memory if the message
> > traffic is heavy. If I could access the field "data" in class JArray, the
> > problem would be solved. Unfortunately, it's a private field.  
> 
> Use the friend function 
> 	template<class T> inline T* elements(JArray<T>& x);

I just realized that I didn't really give an answer to what you were asking.
What you really should do is to allocate the memory as a normal Java array, then 
extract a pointer to the underlying data using elements() and use this preallocated 
memory when constructing the message on the C side.

-- 
Rolf W. Rasmussen                              "Printer friendly format"?
                                                     I must be a printer.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]