The TGBufferStream class is a metastream class which provides buffering capabilities for another stream. This class manages buffering input and output for the stream passed to it in the constructor. For lots of small reads and writes especially with file i/o (such as the TFileStream class), the TGBufferStream class can improve performance.
The TGBufferStream class is based largely on the TS_BufferStream class from "Secrets of Delphi 2" by Ray Lischner. Modified and used here by his kind permission.
Namespace: GStreams
Delphi
|
type
TGBufferStream = class(TStream)
end;
|
|
Name
|
Description
|
|
Buffer
|
Represents property Buffer.
|
|
BufferEnd
|
Represents property BufferEnd.
|
|
BufferPosition
|
Represents property BufferPosition.
|
|
BufferPtr
|
Represents property BufferPtr.
|
|
BufferSize
|
The BufferSize property specifies the size of the buffer created by the stream, i.e., the smallest number of bytes that are read or written at once (except for when the buffer is flushed). The size of the buffer can make a big difference in the efficiency of the object. The default buffer size is 8192 bytes.
|
|
OnFillBuffer
|
Occurs whenever the buffer is refilled from the stream.
Write an OnFillBuffer event when you want to take action every time the buffer is filled.
|
|
OnFlushBuffer
|
Occurs when the buffer is flushed of all of its contents and written to the stream.
Write an OnFlushBuffer event handler when you want to take some action when the buffer is flushed.
|
|
State
|
Specifies whether the buffer is being used for reading or writing.
The unknown state occurs when the buffer is created, flushed, or the stream has been completely read.
|
|
Stream
|
Represents property Stream.
|
Top
|
The following code shows how to use the TGBufferStream class to buffer the file i/o:
Delphi
|
var
FileStream: TFileStream;
Stream: TGBufferStream;
begin
FileStream := TFileStream.Create( FileName, fmOpenRead );
try
Stream := TGBufferStream.Create( FileStream );
try
// Lots of buffer reads here
finally
Stream.Free;
end;
finally
FileStream.Free;
end;
end;
|
|