[fpc-pascal] Fixed record files

James Richters james at productionautomation.net
Sun Jul 9 20:12:23 CEST 2017


I prefer performance over size, The only reason 'GC' was a byte was because it didn't really need to be a word, however it wouldn't hut to be a word anyway, so I could just use this:

Type
      DrawCMD = Record
                   GC: Word;
                   PX,PY,PZ,GX,GY,GZ,GI,GJ,R,SA,EA:Double;
                End;

I don't understand "packed record" could you elaborate?

James
-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Ched
Sent: Sunday, July 09, 2017 12:01 PM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] Fixed record files

Hello,

I'll try something like

If filesize(drawfile)>0 then
    Seek(drawfile, sizeof(drawfile)-1)
else
    "empty file";

For portability of you file and software, I recommand you to use a "packed record" with an internal forced word-align of the double data. If size matters, no need to align.

Type
      DrawCMD = Record

                   GC: Byte;
                   ______: byte; { no use axcept to force align on words for speed on certain systems }

                   PX,PY,PZ,GX,GY,GZ,GI,GJ,R,SA,EA:Double;

                End;

This can also be uses for memory access, as on some processors, word aligning data can save some cpu cycles with reference to non aligned data for data longer than one byte/char.

Chers, Ched




Le 09.07.2017 à 13:45, James Richters a écrit :
> I have a few questions about fixed record files.  I have the following:
> 
> Type
> 
>     DrawCMD = Record
> 
>                  GC: Byte;
> 
>                  PX,PY,PZ,GX,GY,GZ,GI,GJ,R,SA,EA:Double;
> 
>               End;
> 
> Var
> 
>    DrawFile                    : File Of DrawCMD;
> 
>    Drawinfo                    : DrawCMD;
> 
> I wish to get to the end of the file and read the last record.  Currently I am doing it like this:
> 
>           Reset(DrawFile);
> 
>           while not eof(DrawFile) do
> 
>              begin
> 
>                 Read(DrawFile,DrawInfo);
> 
>              End;
> 
> When this finishes Drawinfo contains the last record of the file.  But 
> I’m wondering if there is a better way since it’s a file of fixed records.
> 
> I’m also wondering if there is a way to insert a record at the 
> beginning of the file, or in the middle of the file without doing 
> something like copying the entire file to a temp file, then re-writing the entire new file in the desired order?
> 
> James
> 
> 
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list