Boost logo

Boost :

Subject: Re: [boost] [optional] memory use for optional refs and ptrs
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-10-07 09:25:19


On 10/07/10 06:22, Stewart, Robert wrote:
[snip]
> I was suggesting that this:
>
> struct P
> {
> short s;
> char c;
> short t;
> char d;
> };
>
> could occupy less space than if the chars and shorts were reversed.
> That is, that P::c could occupy padding between P::s and P::t and
> P::d could occupy padding between a P instance and something
> following it in another composite. Doing so would not violate an
> ABI, unless the ABI specifically disallowed it, because it can be
> established as the expected layout in those cases.
>
The code:

  https://svn.boost.org/trac/boost/browser/sandbox
    /variadic_templates/libs/composite_storage
    /sandbox/layout_all.1.cpp

produces output shown in the attachment.
tagPs is with char's first, Ptags is iwht char's 2nd.
Both sizes are same:

 sizeof(tagPs)=8
 sizeof(Ptags)=8

the other output shows the alignments and offsets of each
component was well as the padding. The offsets are listed
starting from last to first element in the structs.
the output prefixed with layout0 shows the layout for
an empty struct.

HTH.
-Larry




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