graemedouglas / LittleD

A relational database for embedded devices and sensors nodes
Apache License 2.0
726 stars 51 forks source link

Structure layout is inefficient #7

Open pfalcon opened 9 years ago

pfalcon commented 9 years ago

Take as an example:

struct clausenode
{
        db_uint8                bcode;          /**< Binary code data for
                                                     clause. */
        db_uint8                clause_i;       /**< Clause index.
                                                */
        db_int                  start;          /**< Clause start offset.
                                                */
        db_int                  end;            /**< Clause end offset.
                                                */
        db_uint8                terms;          /**< Number of terms in clause.
                                                */
};

This will (on 32-bit platform) waste 2 bytes after clause_i, then 3 bytes after terms. Rather, smaller members should be put towards the end of structure. In that case, only 1 byte will be wasted.