Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!haven!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.misc Subject: Pointers vs. arrays Message-ID: <2742@l.cc.purdue.edu> Date: 17 Nov 90 13:33:56 GMT References: <2732@l.cc.purdue.edu> <5961@lanl.gov> Organization: Purdue University Statistics Department Lines: 29 In article <5961@lanl.gov>, jlg@lanl.gov (Jim Giles) writes: > From article <2732@l.cc.purdue.edu>, by cik@l.cc.purdue.edu (Herman Rubin): > [...] > > Well, here is an example which will definitely not work on all machines. > > It is desired to move 3 bytes into the three least significant bytes of > > a 4-byte word (other sizes are appropriate), and repeat this operation. > > This can be done efficiently by using pointers to words on a machine with > > unaligned reads. Even with overhead for unaligned reads, it is hard to > > see how to do this efficiently otherwise. > It's hard to see what this has to do with the array vs. pointer > issue which was being discussed. It looks to me like you've got > a word that's being 'mapped' as an array of bytes and your loop > is filling the bottom three bytes. Where are the pointers? I neglected to mention that one does not care what goes into the leading byte. The use of pointers here is NOT conforming to the usual standards. The code for this would be *y++ = *x++; decrease x, treated as a byte pointer, by 1; This uses one unaligned read and one aligned write, as compared to three reads and writes. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet) {purdue,pur-ee}!l.cc!hrubin(UUCP)