> > The Mem structure does not appear on disk or in any API (except > as the opaque structure pointer sqlite3_value*) so it can be > revised as needed to force 16-byte alignment. Perhaps > the following definition of Mem would work better: > > struct Mem { > u16 flags; > u8 type; > u8 enc; > char *z; > int n; > i64 i; > double r; > char zShort[NBFS]; > void (*xDel)(void *); > }; > > Assuming the entire structure is 16-byte aligned and pointers > and integers are all 8-bytes and 8-byte aligned, then there > would be 4 bytes of padding between Mem.enc and Mem.z. This > would result in zShort appearing on a 16-byte boundary, would > it not? >
Not exactly, since 'int' is still 4 bytes on Linux ia64. long/size_t is 8 bytes. In fact, I think that the rightest thing here would be to put zShort at the beginning of the structure, because in this case it would get the same alignment as returned from malloc and the rest of fields are strictly typed so that they are aligned by compiler properly. But when I try to put zShort at the beginning, some strange thing happens - SQLite doesn't like it. I start SQLite shell, and it says immediately (or when I create a simple table): D:\src\3rd-parties\sqlitecomp\bin\windows-x32>sqlite3-test.exe test.db SQL error: malformed database schema Can't prepare statement: no such table: test Reproduced on Windows x86 and Linux ia64. -- Alexei Alexandrov