Joe Wilson wrote:
You could save a few bytes in some sqlite internal structs if you'd
use C bitfields for boolean flags:
For example:
struct MemPage {
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
u8 idxShift; /* True if Cell indices have changed */
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
u8 intKey; /* True if intkey flag is set */
u8 leaf; /* True if leaf flag is set */
u8 zeroData; /* True if table stores keys only */
u8 leafData; /* True if tables stores data on leaves only */
u8 hasData; /* True if this page stores data */
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
u16 maxLocal; /* Copy of Btree.maxLocal or Btree.maxLeaf */
u16 minLocal; /* Copy of Btree.minLocal or Btree.minLeaf */
u16 cellOffset; /* Index in aData of first cell pointer */
u16 idxParent; /* Index in parent of this node */
u16 nFree; /* Number of free bytes on the page */
u16 nCell; /* Number of cells on this page, local and ovfl */
struct _OvflCell { /* Cells that will not fit on aData[] */
u8 *pCell; /* Pointers to the body of the overflow cell */
u16 idx; /* Insert this cell before idx-th non-overflow cell */
} aOvfl[5];
BtShared *pBt; /* Pointer back to BTree structure */
u8 *aData; /* Pointer back to the start of the page */
DbPage *pDbPage; /* Pager page handle */
Pgno pgno; /* Page number for this page */
MemPage *pParent; /* The parent of this page. NULL for root */
};
struct MemPage2 {
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
u8 isInit:1; /* True if previously initialized. MUST BE FIRST! */
u8 idxShift:1; /* True if Cell indices have changed */
u8 intKey:1; /* True if intkey flag is set */
u8 leaf:1; /* True if leaf flag is set */
u8 zeroData:1; /* True if table stores keys only */
u8 leafData:1; /* True if tables stores data on leaves only */
u8 hasData:1; /* True if this page stores data */
u16 maxLocal; /* Copy of Btree.maxLocal or Btree.maxLeaf */
u16 minLocal; /* Copy of Btree.minLocal or Btree.minLeaf */
u16 cellOffset; /* Index in aData of first cell pointer */
u16 idxParent; /* Index in parent of this node */
u16 nFree; /* Number of free bytes on the page */
u16 nCell; /* Number of cells on this page, local and ovfl */
struct _OvflCell { /* Cells that will not fit on aData[] */
u8 *pCell; /* Pointers to the body of the overflow cell */
u16 idx; /* Insert this cell before idx-th non-overflow cell */
} aOvfl[5];
BtShared *pBt; /* Pointer back to BTree structure */
u8 *aData; /* Pointer back to the start of the page */
DbPage *pDbPage; /* Pager page handle */
Pgno pgno; /* Page number for this page */
MemPage *pParent; /* The parent of this page. NULL for root */
};
sizeof(struct MemPage) = 84
sizeof(struct MemPage2) = 76
Or is there a C portability issue?
Joe,
You must have missed the comment on this line:
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
There must be some code that uses char pointers to check the first byte
of these structures. So this can't be combined as easily.
Bit fields can offer some space savings, but they are slower since the
generated code must do masking and shifting when reading and setting
them. There are also some issues with regard to the ordering and layout
of bitifleds in cross platform applications. I suspect that is the
reason they aren't used.
Dennis Cote
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------