Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: question about records

  1. #11
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Interesting! I wonder what other complexities could arise from this. For example, if I were to serialize and stream a record from an architecture with different alignment, and pump the data directly into a record, would I get what I expected when querying the contents? My knowledge is lacking in this. When reading/writing various binary formats from/to a disk into/from records, I always set my record to be packed for fear of the byte alignment of an unpacked record resulting in unexpected values.

    Can anyone tell me off the top of their heads if my fears are justified? I think some research is in order

    EDIT : OK. from what I've read, you should not stream an unpacked, boundry aligned record to a file or across a network unless you can ensure that it will be read back or recieved with the same byte alignment. the padding of the record will get written too!

    For streams/writing to a hard disk (or any other such bulk transfer of a record to some form of media) you should always use packed records! (unless you want to read that data on multiple architechures such as PowerPC, Arm etc, see 'endiness' below)

    you should only use non packed records if they will only ever live in memory, at run time. And should do in this situation because of the performance improvments offered by byte aligned data.

    In situations where you want the speed of byte aligned but still want to write that data out to a disk, it's highly advisable that you write it an element at a time, rather than just streaming from the address of the record using the size of the record.

    If you are writing your code to run on architectures with different endiness you should never just stream a record, always break it down into it's component parts for endiness conversion!

    I hope this has added to the discussion
    Last edited by phibermon; 15-10-2010 at 06:57 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  2. #12
    My guess is that byte alignment is determined by the compiler settings. You have to make sure that these are always the same for each program that is using your files containing the serialized records. I tend to leave these settings alone.

    The case statement inside a record doesn't actually add any complexity AFAIK. It only gives you different ways to adress exactly the same memory.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #13
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Yes that is my understanding also. I believe there's another keyword called ABSOLUTE (http://www.delphigeist.com/2009/09/a...directive.html) that lets you do somthing similar to a variant record. A stated by Chronozphere, Variant records can be thought of two or more sets of variables that share the same memory. Absolute lets you do this as well, but directly for variables rather than in a record type.

    (although I read that there's problems with this on architectures that force storage on the stack rather than allowing it to sit in a register. or the other way around, I forget)
    Last edited by phibermon; 15-10-2010 at 07:45 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •