Re: [fpc-pascal] Fixed record files

2017-07-09 Thread James Richters
Thanks for the link.   For best compatibility should I make it:

 

Type

  DrawCMD = Packed Record

   GC: Word;

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

End;

 

 

Or 

 

Type

 {$PackRecords 2}   
  DrawCMD =  Record

   GC: Word;

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

End;

 {$PackRecords default}

 

Or am I not understanding this correctly?

 

James

 

From: fpc-pascal [mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of 
Vojtech Cihák
Sent: Sunday, July 09, 2017 2:44 PM
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
Subject: Re: [fpc-pascal] Fixed record files

 

Hi,

 

"packed record" is for compatibility. Its guaranteed that inner alignment and 
size of record will be always the same and will not change in future versions 
of compiler, unlike the plain "record".

 

https://www.freepascal.org/docs-html/ref/refsu15.html

 

V.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Fixed record files

2017-07-09 Thread Vojtěch Čihák

Hi,
 
"packed record" is for compatibility. Its guaranteed that inner alignment and size of 
record will be always the same and will not change in future versions of compiler, unlike the plain 
"record".
 
https://www.freepascal.org/docs-html/ref/refsu15.html
 
V.
__

Od: "James Richters" <ja...@productionautomation.net>
Komu: "'FPC-Pascal users discussions'" <fpc-pascal@lists.freepascal.org>
Datum: 09.07.2017 20:12
Předmět: Re: [fpc-pascal] Fixed record files



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

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 
<http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Fixed record files

2017-07-09 Thread James Richters
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-boun...@lists.freepascal.org] On Behalf Of 
Ched
Sent: Sunday, July 09, 2017 12:01 PM
To: FPC-Pascal users discussions <fpc-pascal@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@lists.freepascal.org 
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Fixed record files

2017-07-09 Thread Ched

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@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal