[fpc-devel] Class field reordering

Jonas Maebe jonas.maebe at elis.ugent.be
Sat Jul 14 14:07:30 CEST 2012


On 14 Jul 2012, at 08:00, Martin Schreiber wrote:

> On Saturday 14 July 2012 07:50:58 Martin Schreiber wrote:
>> On Saturday 14 July 2012 01:44:39 Jonas Maebe wrote:
>>> I've implemented an optimization that reorders the instance fields of
>>> Delphi-style classes (and only of Delphi-style classes) to minimise
>>> memory gaps caused by alignment differences and odd sizes. The effect
>>> is the same as when you would change the order of the fields in the
>>> source code to achieve this effect.
>> 
>> I sometimes need "cracker" classes in MSEide and MSEgui to fix bugs and
>> make extensinsions for FCL classes in order to access private fields
>> (examples TDataset, TParam, TField, TFiler, TReader, TWriter, TComponent).
>> Is it guaranteed that the local definitions have the same layout as the
>> definition in the FCL unit?

If you you use the same packrecords setting, yes (I doubt any such fcl units contain packrecords directives though, in which case they'll use the default).

> Hmm, up to now I listed in the cracker classes fields up to the last private 
> field I need to access so the cracker classes would not brake by changing or 
> adding successive fields in the original classes. I assume now it is 
> necessary to always list all fields of the original class.

If would you want to use that optimization, then yes. "Working around" the type system of the language is however generally asking for trouble, regardless of what reason you do it for.


Jonas


More information about the fpc-devel mailing list