Unit 'bufstream' Package
[Overview][Constants][Classes][Index] [#fcl]

TBufferedFileStream

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Implements a buffered file stream with a multi-page buffer.

Declaration

Source position: bufstream.pp line 88

type TBufferedFileStream = class(TFileStream)

public

  constructor Create();

  

Constructor for the class instance.

  destructor Destroy; override;

  

Destructor for the class instance.

  function Seek();

  

Moves the position in the buffer relative to the specified origin.

  function Read(); override;

  

Reads the specified number of bytes into the Buffer parameter.

  function Write(); override;

  

Writes the specified number of bytes in Buffer to the internal page buffer(s).

  procedure Flush;

  

Flushes modified pages in the buffer to the file stream.

  procedure InitializeCache();

  

Re-initializes the internal buffer for the buffered file stream.

end;

Inheritance

TBufferedFileStream

  

Implements a buffered file stream with a multi-page buffer.

|

TFileStream

|

THandleStream

|

TStream

|

TObject

Description

TBufferedFileStream is a TFileStream descendant which implements a buffered file stream. It provides a buffer with multiple pages used for random read / write access in the file stream.

By default, It uses a fixed-size buffer consisting of 8 pages with a 4,096 bytes per page. Both page count and page size configurable using the InitializeCache method in the class. The buffer is automatically maintained when the stream size or position is changed, and when reading or writing content to/from the stream.

Pages which have been modified in the buffer are written to the file stream as needed (all pages are used and a read/write operation is performed), when the Flush method is called, and when the class instance is freed. Thus, the class will never use more than the total size obtained by multiplying the CacheBlockSize and aCacheBlockCount arguments to InitializeCache.

This class is suitable when you need to do a lot of random access to a file: hence the use of different pages of configurable size. If you simply wish to speed up sequential reads you better use TReadBufStream or TWriteBufStream for speeding up sequential writes.

See also

TFileStream

THandleStream

TStream

TReadBufStream

  

Read-only buffered stream.

TWriteBufStream

  

Write-only buffered stream.


Documentation generated on: Jan 30 2024