Reordered class fields?

bearophile bearophileHUGS at lycos.com
Mon Oct 22 01:48:33 PDT 2012


Simen Kjaeraas:

> The current GC always allocates a power of two, with a minimum 
> of 16
> bytes. You should see an effect if you make a class that will 
> be above such a threshold without reordering, and below with.

Right.


> Nothing bad can come of it.

OK :-)

----------------------

Jacob Carlborg:

> Are D allowed to reorder the class fields?

This page says:
http://dlang.org/class.html

>The D compiler is free to rearrange the order of fields in a 
>class to optimally pack them in an implementation-defined 
>manner. Consider the fields much like the local variables in a 
>function - the compiler assigns some to registers and shuffles 
>others around all to get the optimal stack frame layout. This 
>frees the code designer to organize the fields in a manner that 
>makes the code more readable rather than being forced to 
>organize it according to machine optimization rules. Explicit 
>control of field layout is provided by struct/union types, not 
>classes.<

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list