gnegg programming with passion

13Jan/090

pointers, sizes

Just a small remember for myself:

If

?View Code DELPHI
TMyRecord = record
  pointer1: pointer;
  pointer2: pointer;
  pointer3: pointer;
  pointer4: pointer
end;
PMyRecord = ^TMyRecord;

then

?View Code DELPHI
  sizeof(TMyRecord) <> sizeof(PMyRecord)

So

?View Code DELPHI
  var rec: PMyRecord;
 
  rec = AllocMem(sizeof(rec));

is probably not a sensible thing to do (at least not if you intend to actually put something into that space the pointer points to).

At least it began breaking very, very soonish and consistently once TMyRecord got enough members - too bad though that I first looked at the completely wrong space.

Nothing beats the joy of seeing a very non-localized access violation go away after two hours of debugging though.

Tagged as: , No Comments