TMemoryStream
[Properties (by Name)][Methods (by Name)][Events (by Name)]
Standard implementation of a stream that stores its data in memory
Declaration
Source position: classesh.inc line 1213
Type
TMemoryStream = class (TCustomMemoryStream)
private
FCapacity : PtrInt;
procedure SetCapacity(NewCapacity: PtrInt);
protected
function Realloc(var NewCapacity: PtrInt) : Pointer; Virtual;
Capacity : PtrInt;
public
destructor Destroy; Override;
procedure Clear;
procedure LoadFromStream(Stream: TStream);
procedure LoadFromFile(const FileName: string);
procedure SetSize(const NewSize: Int64); Override;
function Write(const Buffer; Count: LongInt) : LongInt; Override;
end
;
Description
TMemoryStream is a TStream descendant that stores it's data in memory. It descends directly from TCustomMemoryStream and implements the necessary to allocate and de-allocate memory directly from the heap. It implements the Write method which is missing in TCustomMemoryStream.
TMemoryStream also introduces methods to load the contents of another stream or a file into the memory stream.
It is not necessary to do any memory management manually, as the stream will allocate or de-allocate memory as needed. When the stream is freed, all allocated memory will be freed as well.
Members
| Member | Type | Visibility | Description |
|---|---|---|---|
| Capacity | Property | protected | Current capacity of the stream. |
| Clear | Method | public | Zeroes the position, capacity and size of the stream. |
| Destroy | Method | public | Frees any allocated memory and destroys the memory stream. |
| FCapacity | Field | private | |
| LoadFromFile | Method | public | Loads the contents of a file into memory. |
| LoadFromStream | Method | public | Loads the contents of a stream into memory. |
| Realloc | Method | protected | Sets the new capacity for the memory stream |
| SetCapacity | Method | private | |
| SetSize | Method | public | Sets the size for the memory stream. |
| Write | Method | public | Writes data to the stream's memory. |
Inheritance
| Class | Description |
|---|---|
| TMemoryStream | Standard implementation of a stream that stores its data in memory |
See also
| Name | Description |
|---|---|
| PtrInt | Signed integer type with same size as Pointer. |
| PtrInt | Signed integer type with same size as Pointer. |
| TCustomMemoryStream | Abstract stream that stores its data in memory. |
| TStream | Base class for streams. |