Grijjy FoundationUnits Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
Class TgoRingBuffer
Unit
Grijjy.Collections
Declaration
type TgoRingBuffer<T:record> = class(TObject)
Description
A ring buffer (aka "circular buffer"). This is a fixed-size buffer as if it were connected end-to-end. Lends itself for buffering data streams.
This is a generic implementation that you can use to buffer any value type (such as integers, bytes, floats and records). It does not work with reference types (such as strings, objects and interfaces).
All "Count"s used in this class refer the a number of elements (of type T), and not to a number of bytes (unless T is an 8-bit value).
Hierarchy
Overview
Methods
|
constructor Create(const ACapacity: Integer); |
|
function Write(const AData: TArray<T>): Integer; overload; |
|
function Write(const AData: array of T): Integer; overload; |
|
function Write(const AData: TArray<T>; const AIndex, ACount: Integer): Integer; overload; |
|
function Write(const AData: array of T; const AIndex, ACount: Integer): Integer; overload; |
|
function TryWrite(const AData: TArray<T>): Boolean; overload; |
|
function TryWrite(const AData: array of T): Boolean; overload; |
|
function TryWrite(const AData: TArray<T>; const AIndex, ACount: Integer): Boolean; overload; |
|
function TryWrite(const AData: array of T; const AIndex, ACount: Integer): Boolean; overload; |
|
function Read(var AData: TArray<T>): Integer; overload; |
|
function Read(var AData: array of T): Integer; overload; |
|
function Read(var AData: TArray<T>; const AIndex, ACount: Integer): Integer; overload; |
|
function Read(var AData: array of T; const AIndex, ACount: Integer): Integer; overload; |
|
function TryRead(var AData: TArray<T>): Boolean; overload; |
|
function TryRead(var AData: array of T): Boolean; overload; |
|
function TryRead(var AData: TArray<T>; const AIndex, ACount: Integer): Boolean; overload; |
|
function TryRead(var AData: array of T; const AIndex, ACount: Integer): Boolean; overload; |
Properties
Description
Methods
|
constructor Create(const ACapacity: Integer); |
Creates a ring buffer of a given size.
Parameters
- ACapacity
- the number of elements (of type T) that the buffer will hold.
|
|
function Write(const AData: TArray<T>): Integer; overload; |
Writes a data array to the buffer.
Parameters
- AData
- the data to write to the buffer.
Returns
The number of elements written to the buffer. This may be less than the length of AData in case the buffer has become full. |
|
function Write(const AData: array of T): Integer; overload; |
|
|
function Write(const AData: TArray<T>; const AIndex, ACount: Integer): Integer; overload; |
Writes a segment of a data array to the buffer.
AIndex and ACount must point to a valid segment in the array.
Parameters
- AData
- array containing the data to write to the buffer.
- AIndex
- start index into AData.
- ACount
- number of elements in AData to write to the buffer, starting at AIndex.
Returns
The number of elements written to the buffer. This may be less than ACount in case the buffer has become full. |
|
function Write(const AData: array of T; const AIndex, ACount: Integer): Integer; overload; |
|
|
function TryWrite(const AData: TArray<T>): Boolean; overload; |
Tries to write a data array to the buffer. Either the entire operation will succeed or fail. Unlike Write, no data will be written if this operation would lead to an overflow.
Parameters
- AData
- the data to write to the buffer.
Returns
True if the data was successfully written, or False in case the buffer would overflow if the data would be written. In that case, no data is written to the buffer at all. |
|
function TryWrite(const AData: array of T): Boolean; overload; |
|
|
function TryWrite(const AData: TArray<T>; const AIndex, ACount: Integer): Boolean; overload; |
Tries to write a segment of a data array to the buffer. Either the entire operation will succeed or fail. Unlike Write, no data will be written if this operation would lead to an overflow.
AIndex and ACount must point to a valid segment in the array.
Parameters
- AData
- array containing the data to write to the buffer.
- AIndex
- start index into AData.
- ACount
- number of elements in AData to write to the buffer, starting at AIndex.
Returns
True if the data was successfully written, or False in case the buffer would overflow if the data would be written. In that case, no data is written to the buffer at all. |
|
function TryWrite(const AData: array of T; const AIndex, ACount: Integer): Boolean; overload; |
|
|
function Read(var AData: TArray<T>): Integer; overload; |
Reads to a data array from the buffer.
Parameters
- AData
- the data array that will be filled with data read from the buffer. It will try to read Length(AData) elements to fill the entire array.
Returns
The number of elements read from buffer. This may be less than the length of AData in case the buffer did not have enough data available. |
|
function Read(var AData: array of T): Integer; overload; |
|
|
function Read(var AData: TArray<T>; const AIndex, ACount: Integer): Integer; overload; |
Reads to a segment of a data array from the buffer.
AIndex and ACount must point to a valid segment in the array.
Parameters
- AData
- the data array that will be filled with data read from the buffer.
- AIndex
- start index into AData.
- ACount
- the number of elements to read into AData, starting at AIndex.
Returns
The number of elements read from buffer. This may be less than ACount in case the buffer did not have enough data available. |
|
function Read(var AData: array of T; const AIndex, ACount: Integer): Integer; overload; |
|
|
function TryRead(var AData: TArray<T>): Boolean; overload; |
Tries to read to a data array from the buffer. Either the entire operation will succeed or fail. Unlike Read, no data will be read if the buffer does not have enough data available.
Parameters
- AData
- the data array that will be filled with data read from the buffer. It will try to read Length(AData) elements to fill the entire array.
Returns
True if the data was successfully read, or False if the buffer does not have enough data available to read the requested amount. In that case, no data is read from the buffer at all. |
|
function TryRead(var AData: array of T): Boolean; overload; |
|
|
function TryRead(var AData: TArray<T>; const AIndex, ACount: Integer): Boolean; overload; |
Tries to read to a segment of a data array from the buffer. Either the entire operation will succeed or fail. Unlike Read, no data will be read if the buffer does not have enough data available.
AIndex and ACount must point to a valid segment in the array.
Parameters
- AData
- the data array that will be filled with data read from the buffer.
- AIndex
- start index into AData.
- ACount
- the number of elements to read into AData, starting at AIndex.
Returns
True if the data was successfully read, or False if the buffer does not have enough data available to read the requested amount. In that case, no data is read from the buffer at all. |
|
function TryRead(var AData: array of T; const AIndex, ACount: Integer): Boolean; overload; |
|
Properties
|
property Capacity: Integer read FCapacity; |
The capacity of the ring buffer (in number of elements), as passed to the constructor.
|
|
property Count: Integer read FCount; |
The number of elements currently in the buffer (available for reading).
|
|
property Available: Integer read GetAvailable; |
The number of elements available for writing (= Capacity - Count).
|
Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26
|