| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On Mar 13, 2006, at 1:22 PM, Greg Guerin wrote:
rohit dhamija wrote:
Actually in my application, java is communicating with C code through
JNI-java native interface. I am getting a byte array from C code that i am
further parsing in my java code.
In this situation i was facing byte swaps. So need to get the data into
correct format.
I suggest writing a JNI method that your Java code calls in order to
determine the correct byte-ordering. It's trivial to write C code that
senses native byte-ordering, and it will automatically work everywhere the
C code itself is compiled and run.
In my view, you shouldn't ever write Java code that independently infers
byte-ordering from "ppc" or "i386" or any other magic values not tied to
the actual native code. There would be no such externalities.
Another possibility is to use java.nio.ByteOrder.nativeOrder(). The only
reason for not using it is it only exists on J2SE 1.4+. Depending on what
Java version you're targeting, maybe that's OK.
If NIO is OK, you may want to look at using Buffers and applying native
ByteOrder, to simplify the communication with the JNI code. I would
recommend direct buffers, too, but there's an apparent GC problem with them
(search the list archives for terms "direct buffer GC").
-- GG
| References: | |
| >Re: Byte swapping routines for java (From: Greg Guerin <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.