While playing around with Delphi and the RTTI for a small debug tool I'm working on, I noticed that Delphi always allocates extra zeroes at the end of every class instance.
This is the same in both 32bit and 64bit, just the sizes are different. Here's what happens in 64bit for TObject.Create:
TObject.InstanceSizereturn 16.- These 16 bytes are allocated for the instance and initialised to zeroes.
- The first 8 bytes are assigned a pointer to
TClass. - The second 8 bytes are left as zeroes.
Any sub-class will always have these final 8 bytes of zeroes after the other fields.
My question is this: why does Delphi include these trailing zeroes in the instance? The only reason I can come up with is that it is some sort of safety feature, but I am unable to see how this would help.