Tail pad optimization, cache friendlyness and C++ interrop

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 10 21:11:53 PDT 2014


On 6/10/2014 7:44 PM, deadalnix wrote:
> On Wednesday, 11 June 2014 at 02:10:18 UTC, Walter Bright wrote:
>> On 6/10/2014 5:27 PM, deadalnix wrote:
>>> I'm talking about structs, not classes.
>>
>> Ok, but since D structs do not inherit, how does tail pad optimization apply?
>
> struct S1 {
>       int a;
>       byte b;
> }
>
> struct S2 {
>       S1 s1;
>       char c;
> }

Hmm, this could have serious problems with the following:

S1 s1;
S2 s2;
s2.c = 3;
memcpy(&s2.s1, &s1, sizeof(S1)); // Oops! stomped on s2.c



More information about the Digitalmars-d mailing list