On Tue, Feb 19, 2013 at 10:04:07AM -0500, Jeff Cody wrote: > On Tue, Feb 19, 2013 at 03:30:10PM +0100, Kevin Wolf wrote: > > The whole point of packed structs is to enable the unaligned data > > access, so yes, you're right with that. But in my opinion declaring the > > struct packed and letting the compiler deal with unaligned data is > > clearly superior to doing it manually. I mean, this is the kind of > > things that compilers are for. > > I have no doubt the compiler can deal with the unalignment. But we > can do things the compiler essentially can't, when it comes to data > layout. Maybe I am engaging in too much micro-optimization here, but > the way the compiler has to deal with it is by additional > instructions, since it can't do anything about the data structure > itself.
We're talking about the header here. It's read exactly once and presumably not updated very often. The performance of these operations doesn't matter at all. Saving lines of code that could potentially contain bugs does matter. > That said, since both of the block maintainers prefer packed structs, > I will change over to those (sigh - and I was so happy with those > macros! :) ). You can (or actually should) still copy those part to BDRVVHDXState that the driver frequently accesses. Things just become a bit less magic when you access members of a packed struct instead of random offsets. Kevin