From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,5bcae0baee38d312 X-Google-Attributes: gidfee84,public From: edo@cis.ohio-state.edu (Eric Osborne) Subject: Re: unaligned access Date: 1995/05/22 Message-ID: <3pr23gINN4ru@bumble.cis.ohio-state.edu>#1/1 X-Deja-AN: 103111498 distribution: usa references: <3plnvd$gks@chomolangma.expersoft.com> organization: The Ohio State University, Department of Computer and Information Science newsgroups: comp.unix.osf.osf1 I ported a bunch of code, including AT&T's BaseWorX networking software and the USL ASN.1 compiler, to Digital Alpha platforms a while back. One basic failing that became fairly quickly evident was the fact that XDR and much other code really assumes that a long is 32 bits - even if you do the right thing on the Alpha machine, the receiver will likely munge the whole thing on the other end. I did the ports under non-disclosure, so I really can't tell you specifics of how I solved problems in that code, but here's what I'd do if I were you. I'd define a set of routines that send a tag (one byte is probably enough) with your data. Have the tags relate to a set of enumerated values, and use them as indices into a set of data decoding functions. This has many merits. For one thing, you can avoid superfluous byte swapping. Tag the data, and send it unencoded. Let the receiver decode if necessary. With this technique, you will never have to waste cycles encoding data between machines with like architectures. For instance, an Intel processor could use data as-is from an Alpha machine, as long as the word length was appropriate. The tag can denote anything from strings to 64 bit longs to whatever. I believe that the DCE encoding routines use a mechanism similar to this. XDR and many other routines which put data into "network order" actually force big-endian byte order - the routines are biased in that fashion, and impose senseless performance penalties on little-endian systems, especially when communicating with another little-endian system. And, all architecture biases aside, there are a whole lot more little-endian systems than there are any thing else, just because of Intel. Your alignment problem probably stems from some assumption in the code that it can align objects on 4 byte boundaries. That doesn't work for many data types on the Alpha machines. Hope that helps. Eric Osborne