Read lots of records at the same time from a typed file 
Author Message
 Read lots of records at the same time from a typed file

I want to read lots of records at the same time from a typed file.
How can I do it?

--
< Mark >



Wed, 18 Jun 1902 08:00:00 GMT  
 Read lots of records at the same time from a typed file

Quote:
> I want to read lots of records at the same time from a typed file.
> How can I do it?

   There are several ways that I can think of, one using BlockRead, which
can read in large amount(s) of data with a single I/o.  First, you could
allocate a buffer of N times the record size and fill it with a BlockRead
of that many bytes (but handling the short block at the end of file in a
special manner).  You will have to "parse" the records from the buffer
the data way read into, but that's easy (with Move).
   A second way is to use the typed file Read with more than 1 variable
in the argument list: Read (file_var, R1, R2, R3, R4, etc.).


Wed, 18 Jun 1902 08:00:00 GMT  
 Read lots of records at the same time from a typed file



Quote:
>> I want to read lots of records at the same time from a typed file.
>> How can I do it?

>   There are several ways that I can think of, one using BlockRead, which
>can read in large amount(s) of data with a single I/o.  First, you could
>allocate a buffer of N times the record size and fill it with a BlockRead
>of that many bytes (but handling the short block at the end of file in a
>special manner).  You will have to "parse" the records from the buffer
>the data way read into, but that's easy (with Move).

Not necessarily, it could also be done with variant records, absolute
variables, or typecasting:

type
  TMyRec = record
    value : integer
  end ;

  TVarInput = record
    case byte of
      0 : ( RecArray : array [1..10] of TMyRec ) ;
      1 : ( ReadBuff : array [0..19] of byte ) ;
  end ;

var
  MyBuff : TVarInput ;
  x : integer ;
begin
  BlockRead( F, MyBuff.ReadBuff, SizeOf( MyBuff.ReadBuff )) ;
  X := MyBuff.RecArray[3].Value ;

Quote:
>   A second way is to use the typed file Read with more than 1 variable
>in the argument list: Read (file_var, R1, R2, R3, R4, etc.).

That'll work too, or how about into an array:

var
  RecArray : array [1..10] of TMyRec ;

begin
  Read( F, RecArray[1], RecArray[2], RecArray[3]... RecArray[10] ) ;

Regards,

Stephen Posey



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DBASE:How can i add lot of records without updating index file

2. APPEND to a file of record typed file

3. How to file/record lock a typed file.

4. Optimizing query time w/lots of cols?

5. Reading typed files

6. Reading database-type files

7. Reading Blockwritten typed files using C

8. Reading Blockwritten typed files using C

9. Need to read type 0 PCX file in TP30

10. Determining the number of records in a typed file

11. Appending record-typed files

12. Record Locking in typed and untyped files??

 

 
Powered by phpBB® Forum Software