Unit 'System' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

SetTextBuf

Set size of text file internal buffer.

Declaration

Source position: systemh.inc line 1476

procedure SetTextBuf(

  var f: Text;

  var Buf

);

procedure SetTextBuf(

  var f: Text;

  var Buf;

  Size: SizeInt

);

Description

SetTextBuf assigns an I/O buffer to a text file. The new buffer is located at Buf and is Size bytes long. If Size is omitted, then SizeOf(Buf) is assumed. The standard buffer of any text file is 128 bytes long. For heavy I/O operations this may prove too slow. The SetTextBuf procedure allows to set a bigger buffer for the I/O of the application, thus reducing the number of system calls, and thus reducing the load on the system resources. The maximum size of the newly assigned buffer is 65355 bytes.

Remark:
  • Never assign a new buffer to an opened file. A new buffer can be assigned immediately after a call to Rewrite, Reset or Append, but not after the file was read from/written to. This may cause loss of data. If a new buffer must be assigned after read/write operations have been performed, the file should be flushed first. This will ensure that the current buffer is emptied.
  • Take care that the assigned buffer is always valid. If a local variable is assigned as a buffer, then after the program exits the local program block, the buffer will no longer be valid, and stack problems may occur.

Errors

No checking on Size is done.

See also

Assign

  

Assign a name to a file.

Reset

  

Open file for reading.

Rewrite

  

Open file for writing.

Append

  

Open a file in append mode.

Example

Program Example61;

{ Program to demonstrate the SetTextBuf function. }

Var
  inout : Text;
  Ch : Char;
  Bufin,Bufout : Array[1..10000] of byte;

begin
  Assign (inaramstr(1));
  Reset (in
  Assign (Fout,paramstr(2));
  Rewrite (Fout);
  { This is harmless before IO has begun }
  { Try this program again on a big file,
    after commenting out the following 2
    lines and recompiling it. }
  SetTextBuf (inufin);
  SetTextBuf (Fout,Bufout);
  While not ofin) do
    begin
    Read (inh);
    write (Fout,ch);
    end;
  Close (in
  Close (Fout);
end.

Documentation generated on: Oct 27 2024