Boost logo

Boost :

Subject: Re: [boost] [optional] memory use for optional refs and ptrs
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-10-06 17:15:15


On 10/06/10 13:19, Larry Evans wrote:
> On 10/06/10 13:05, Larry Evans wrote:
> [snip]
>> A copy of the code posted here:
>>
>> http://article.gmane.org/gmane.comp.lib.boost.devel/209212
>>
>> followed by:
> [snip]
> Further experimentation resulted in the attached which produces output:
>
> sizeof(A)=32
> sizeof(B)=56
> sizeof(A_pairs)=56
> sizeof(A_bools)=40
> sizeof(bools_A)=32
> sizeof(chars_A)=32
>
> So, gathering all tags at start (bools_A and chars_A) saves
> the most space.

The reason sizeof(A) == sizeof(bools_A) is that the 4 bools use
the padding following the int A::a. IOW, bools_A puts the
4 bools where the int A::a is located, followed by the int.
Hence, no extra space is needed. Adding 1 extra bool at the
start causes the sizeof(bools_A) to jump by 8.

This is shown by output of the attached:

alignment_of<A>::value=8
sizeof(A)=32
sizeof(B)=56
sizeof(Atags)=56
sizeof(tagsA)=56
sizeof(A_bools)=40
sizeof(bools_A)=32
sizeof(bools)=4
sizeof(int)=4
alignment_of<bools>::value=1




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk