
On 10/07/10 07:31, Rutger ter Borg wrote:
On 2010-10-07 13:37, Larry Evans wrote:
[snip]
A more complete facility use is here:
https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/libs/com...
[snip]
which shows the padding after the char is 3 in order to make the alignment of the int at 4.
HTH.
-Larry
Thanks,
You're welcome. The reusable part of the code has been refactored into: http://svn.boost.org/svn/boost/sandbox/variadic_templates /boost/composite_storage/utility /show_layout_all_of_aligned.hpp so that it on different struct's rather than just the struct's in the current example driver. The output produced on the example struct's in: https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates /libs/composite_storage/sandbox/layout_all.1.cpp is now in tabular format: A_type =========== ***components*** ---------------- num size align sum_size 1 4 4 4 2 8 8 12 3 8 8 20 4 8 8 28 ***composite*** --------------- num size align pad sum_pad offset 5 32 8 0 0 _ 4 32 8 0 0 24 3 24 8 0 0 16 2 16 8 4 4 8 1 4 4 0 4 0 0 0 1 _ _ _ A_bools_type =========== ***components*** ---------------- num size align sum_size 1 4 4 4 2 8 8 12 3 8 8 20 4 8 8 28 5 1 1 29 6 1 1 30 7 1 1 31 8 1 1 32 ***composite*** --------------- num size align pad sum_pad offset 9 40 8 4 4 _ 8 36 8 0 4 35 7 35 8 0 4 34 6 34 8 0 4 33 5 33 8 0 4 32 4 32 8 0 4 24 3 24 8 0 4 16 2 16 8 4 8 8 1 4 4 0 8 0 0 0 1 _ _ _ bools_A_type =========== ***components*** ---------------- num size align sum_size 1 1 1 1 2 1 1 2 3 1 1 3 4 1 1 4 5 4 4 8 6 8 8 16 7 8 8 24 8 8 8 32 ***composite*** --------------- num size align pad sum_pad offset 9 32 8 0 0 _ 8 32 8 0 0 24 7 24 8 0 0 16 6 16 8 0 0 8 5 8 4 0 0 4 4 4 1 0 0 3 3 3 1 0 0 2 2 2 1 0 0 1 1 1 1 0 0 0 0 0 1 _ _ _ which shows the padding between individual fields and the sum of the padding. This shows why putting the bools first (bools_A_type) saves space. As mentioned before the 4 bools are placed in the padding present in the padding required by A_type; hence, sizeof(A_type) == sizeof(bools_A_type). Hope the tabular output makes it easier to see the reason for space usage. -Larry