From xerces-c-dev Tue Mar 14 01:23:09 2006 From: "Steven T. Hatton" Date: Tue, 14 Mar 2006 01:23:09 +0000 To: xerces-c-dev Subject: Re: OT: Data alignment (was: How do I use Xerces strings?) Message-Id: <200603132023.09996.hattons () globalsymmetry ! com> X-MARC-Message: https://marc.info/?l=xerces-c-dev&m=114229946822711 On Monday 13 March 2006 06:41, Axel Weiß wrote: > > Hi Steven, > > the topic of the page you pointed out is how data are aligned in mixed > structures. It is common to these architectures that they have alignment > restrictions when different data formats are accessed: > 8 bit - any address > 16 bit - only even addresses > 32 bit - only addresses that are dividable through 4 > and so on. > > > You /can/ tell the compiler to go ahead and pack the data as tightly > > as possible by ignoring natural alignment boundaries, but doing so > > will probably have a significant negative impact on performace. > > Again, this is only true, if you want to pack misaligned data in > structures. Then the compiler must shift-mask-pack the large misaligned > entities. On some architectures, like i386, this reduces performance > significantly. > > When you are talking about strings, you are talking about arrays, which > may be understood as naturally aligned data assembles. The only relevant > factor that restricts these alignments, is the addressability of the > smallest data unit (called byte). This is 8 bit on any i386 processor, > but maybe 16, 32, 64 or even 128 bit on other processors. Check it out: > what gives > - sizeof(char): _always_ 1, on any architecture > - sizeof(int): 4 on i386 processors (int is 32 bit), 8 on 64-bit > processors (int is 64 bit), but 1 on a TMS320C3x (since int is 32 bit, > but char is also 32 bit) > Thank you. I'm happy to see that someone finally understood the point I have been trying to make. I had originally stated that I didn't expect the size of the data unit to impact memory usage. I then acknowledged that I was wrong about that because data in an array of characters will be contiguous, and strings would be stored as arrays. The rest of the discussion had to do with storing data that was not in an array. Steven --------------------------------------------------------------------- To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org For additional commands, e-mail: c-dev-help@xerces.apache.org