[Overview][Constants][Types][Classes][Procedures and functions][Variables] | Reference for unit 'Classes' (#fcl)

# TMemoryStream

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

Standard implementation of a stream that stores its data in memory

## Declaration

`type TMemoryStream = class(TCustomMemoryStream)`
`protected`
`function Realloc(); virtual;` |  | Sets the new capacity for the memory stream
`property Capacity: LongInt; [rw]` |  | Current capacity of the stream.
`public`
`destructor Destroy; override;` |  | Frees any allocated memory and destroys the memory stream.
`procedure Clear;` |  | Zeroes the position, capacity and size of the stream.
`procedure LoadFromStream();` |  | Loads the contents of a stream into memory.
`procedure LoadFromFile();` |  | Loads the contents of a file into memory.
`procedure SetSize(); override;` |  | Sets the size for the memory stream.
`function Write(); override;` |  | Writes data to the stream's memory.
`end;`

## Inheritance

`TMemoryStream` |  | Standard implementation of a stream that stores its data in memory
`TCustomMemoryStream` |  | Abstract stream that stores its data in memory.
`TStream` |  | Base class for streams.
`TObject`

## Description

TMemoryStream is a TStream descendent that stores it's data in memory. It descends directly from TCustomMemoryStream and implements the necessary to allocate and de-allocate memory diretly 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.

## See also

TCustomMemoryStream |  | Abstract stream that stores its data in memory.
TStream |  | Base class for streams.