[Lazarus] EXC_BAD_ACCESS, Could not access memory

Roland Turcan konf at rotursoft.sk
Mon Apr 27 15:55:02 CEST 2009


Hello All,

I have found some new information about this problem:

1.

TYPE TMyOne =record
               First:integer;
               Second:integer;
             end;

... then the size of this object is 2*4 bytes.

2.

TYPE TMyOne =record
               First:integer;
               Second:double;
             END;

... where I would expect 4 + 8 bytes = 12 bytes
... but the size of this object is 16!


3.

TYPE TMyOne =record
               First:integer;
               Second:extended;
             END;

... where I would expect 4 + 16 bytes = 20 bytes
... but the size of this object is 32!


So this proves me, that compiler tries to align the data structure to
multiplied size of biggest element to which fit all elements.

I have understood this behavior, but this happens me in these cases:

1. Delphi 7
2. Kylix 3
3. Lazarus on Ubuntu
4. Lazarus on PowerPC Mac OS X 10.5

but on Intel Based Mac OS X 10.5 Mini with Intel Duo 2 Core it
DOESN'T. Therefore I have problems with parsing of binaries back to
memory.

I don't expect CPU specific problem, otherwise it would not work
active projects, therefore I think it must be compiler specific
problem.

Do you have any idea?

Thanks in advance.

Greetings, TRoland;


<<< 25.4.2009 9:43 - Roland Turcan "konf at rotursoft.sk" >>>
RT> Hello Diettrich,

RT> To tell the truth this code and style I got from previous developer
RT> and I really don't know why he decided to get the size of header from
RT> the binary instead of getting its size. The fact is, that this
RT> "optimistic variant" of coding is on many places. :-|

RT> TRoland;

RT> <<< 24.4.2009 19:56 - Hans-Peter Diettrich "DrDiettrich1 at aol.com" >>>
HPD>> Roland Turcan schrieb:

>>> BB> How is HeaderLen declared ?
>>> 
>>> Stream.Read (HeaderLen, SIZEOF (HeaderLen));
>>> 
>>> where information header's length is stored into binary.

HPD>> The you should verify that HeaderLen <= SizeOf(FHeader), before
HPD>>    Stream.Read (FHeader, HeaderLen);

HPD>> Otherwise this statement will overwrite the following FItem data, with
HPD>> the fatal consequences you already experienced.

HPD>> When a header will ever change in size (or structure), it's wise to 
HPD>> store a version number in the data files. Then you can read the stored
HPD>> header data into the exactly applicable header type (record), and 
HPD>> convert that record into the current THeader definition, field by field.

HPD>> DoDi

HPD>> _______________________________________________
HPD>> Lazarus mailing list
HPD>> Lazarus at lazarus.freepascal.org
HPD>> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus








-- 
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk




More information about the Lazarus mailing list