ByteOrder issue

Hi,
as it came up to export the data of models like *.obj to the one my engine uses, i ask me the question “what about the byteorder issue with various platforms?”.

As on Windows there is Heighest Bit first i write my datafiles with these byteorder. But how does i have to handle it with other platforms? Is it enough to tell my fileloader (uses NIO bytebuffers) to take all byte with heighest bit regardless the filesystem uses Lowest Bit?
Is that enough or have swap every byte from high to low and back to make my files compatible on most platforms?

Evil

Take a look at the java.nio.Buffer and ist sub classes. You can set the endianess.

Be aware that there (at least was) a bug in the duplicate() and slice() functions where it loses the endianess setting in the new copy so you need to reset it.

JK

I know that i can set the endian by myself via the byteOrder() function, but does i have to switch from heighest to lowest or can i just write and read with heighest even on a lowest bit system? (sounds confusing?)

Java has a standard byte order of its own that is cross paltform.

If all you need to do is read and write to/from java programs just use the normal DataInput/OutputStreams and dont worry about it.

(Buffers also default to Java byte order.)

[quote=“Jeff,post:4,topic:25617”]
More precisely, Java uses the “standard” byte order known as “Network Byte Order”. Network byte order was developed to ensure that [TCP|UDP|*]/IP packets could be understood by all machines that used the Internet. Since Java is a cross-platform language in the Internet era, Network Byte Order made a lot of sense.

It would be nice if all I/O libraries observed network byte order. Sadly, most default to machine byte order, so you have to be careful when you’re reading a file written by a non-Java program. I’ve been bitten by poor endianess on Intel more than once.

Ok, that means i dont have to provide the “byteOrder()” function while i create a bytebuffer to store my data, right?
If so, thanks for the help :slight_smile:

Evil

Right it defeaults to the Java Standard.

Motorola and PowerPC processors are sane enough to use the correct (“network” or “big endian”) byte order. Sadly there aren’t many of those superior processors around… now that Apple has gone to Intel. I don’t think we should hold our breath for Intel to make a processor with a decent architecture… perhaps if they didn’t base their current processors on being backward compatible with a calculator chip from the 70s… so sad… Too bad IBM couldn’t work out their issues with getting the PowerPC up to speed.

What byte order does a Sparc processor use? I would assume that it is also the correct byte order, after all “the network is the computer” :slight_smile:

One of my “high hopes” for Java was that it would free Intel to break with the backwards compatibility since Java applications wouldn’t even need to be recompiled. Once you have the core OS and a JRE ported/recompiled all the existing apps should “just work”. But we all know it is far from that simple. And so we have better achitectures like PPC being emulated on Intel in the new Macs, when it should be the other way around. Somehow I am sure this is all Microsofts fault :slight_smile:

It’s not hard to make a case for Microsoft’s fault in the situation. After all, they DID have the best JVM available back in the 1.1 days. They also had a kick-ass IDE in the form of J++. If they hadn’t screwed the market over with their incompatible extensions, we’d all be using Java desktop applications today.

Gonna be a lot of em around soon in consoles… all the next gen consoles are PPC.

IBM calls their strategy “Power Everywhere” and is very serious about getting PPC into every computing device possible.

Ironically, this is reportedly part of what pushed Apple away from PPC. When noone else muchw as using PPC they had “favoured nation status” and rather abused it by all accounts. Once IBM/Motorola had other larger customers, that status went away and Apple no longer was accord the defference they felt they deserved…

After the Itanium disaster it will take a brave exec at Intel to suggest moving away from their power bsae again.

What I rememerb from my C days… is that Sparc is the same byte order as the Motorola 68000 family, but there are subtle byte packing differences. Again AIR 68000 aligngend everything on word boundaries whereas Sparc aligns on type-boundaries.

Except the desktop. Meaning I no longer can get a PPC based home computer. I have an old BeBox sitting around here somewhere, but I was never able to get it to boot up properly :frowning:

[quote]Ironically, this is reportedly part of what pushed Apple away from PPC. When noone else muchw as using PPC they had “favoured nation status” and rather abused it by all accounts. Once IBM/Motorola had other larger customers, that status went away and Apple no longer was accord the defference they felt they deserved…
[/quote]
If it was I think it was a small part. The speed problems seemed to be the big thing. Though it’s funny how all of Apple’s performance information shows their high-end PPC based systems beating Intel systems with faster clocks… and yet now that’s exactly where they are headed :slight_smile: The power of marketing.