C# Класс Redzen.IO.MemoryBlockStream

A memory backed stream that stores byte data in blocks, this gives improved performance over System.IO.MemoryStream in some circumstances. MemoryStream is backed by a single byte array, hence if the capacity is reached a new byte array must be instantiated and the existing data copied across. In contrast, MemoryBlockStream grows in blocks and therefore avoids copying and re-instantiating large byte arrays. Also note that by using a sufficiently small block size the blocks will avoid being placed onto the large object heap, with various benefits, e.g. avoidance/mitigation of memory fragmentation.
Наследование: Stream
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
EnsureCapacity void
ReadInner int
WriteInner void
ZeroSpareCapacity void

Открытые методы

Метод Описание
Flush ( ) : void

Overrides Stream.Flush so that no action is performed.

MemoryBlockStream ( ) : System

Construct with the default block size.

MemoryBlockStream ( int blockSize ) : System

Construct with the specified block size.

Read ( byte buffer, int offset, int count ) : int

Reads a block of bytes from the stream and writes the data to a buffer.

ReadByte ( ) : int

Reads a byte from the stream.

Seek ( long offset, SeekOrigin origin ) : long

Sets the position within the stream to the specified value.

SetLength ( long value ) : void

Sets the length of the stream to the specified value.

ToArray ( ) : byte[]

Writes the stream contents to a byte array, regardless of the Position property.

Trim ( ) : void

Remove excess blocks from the block list.

Write ( byte buffer, int offset, int count ) : void

Writes a block of bytes into the stream.

WriteByte ( byte value ) : void

Writes a byte to the stream at the current position.

Приватные методы

Метод Описание
EnsureCapacity ( int value ) : void
ReadInner ( byte buff, int offset, int count, int blockIdx, int blockOffset ) : int

Read bytes from the memory stream into the provided buffer, starting at the specified block index and intra-block offset..

WriteInner ( byte buff, int offset, int count, int blockIdx, int blockOffset ) : void

Write bytes into the memory stream, starting at the specified block index and intra-block offset.

ZeroSpareCapacity ( ) : void

Ensure that any existing capacity after _length is zeroed.

Описание методов

Flush() публичный Метод

Overrides Stream.Flush so that no action is performed.
public Flush ( ) : void
Результат void

MemoryBlockStream() публичный Метод

Construct with the default block size.
public MemoryBlockStream ( ) : System
Результат System

MemoryBlockStream() публичный Метод

Construct with the specified block size.
public MemoryBlockStream ( int blockSize ) : System
blockSize int The block size to use.
Результат System

Read() публичный Метод

Reads a block of bytes from the stream and writes the data to a buffer.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The byte array to read bytes into.
offset int The zero-based byte offset in buffer at which to begin storing data from the current stream.
count int The maximum number of bytes to read.
Результат int

ReadByte() публичный Метод

Reads a byte from the stream.
public ReadByte ( ) : int
Результат int

Seek() публичный Метод

Sets the position within the stream to the specified value.
public Seek ( long offset, SeekOrigin origin ) : long
offset long The new position within the stream. This is relative to the loc parameter, and can be positive or negative.
origin SeekOrigin A value of type SeekOrigin, which acts as the seek reference point.
Результат long

SetLength() публичный Метод

Sets the length of the stream to the specified value.
public SetLength ( long value ) : void
value long
Результат void

ToArray() публичный Метод

Writes the stream contents to a byte array, regardless of the Position property.
public ToArray ( ) : byte[]
Результат byte[]

Trim() публичный Метод

Remove excess blocks from the block list.
public Trim ( ) : void
Результат void

Write() публичный Метод

Writes a block of bytes into the stream.
public Write ( byte buffer, int offset, int count ) : void
buffer byte The byte data to write into the stream
offset int The zero-based byte offset in buffer from which to begin copying bytes to the current stream.
count int The maximum number of bytes to write.
Результат void

WriteByte() публичный Метод

Writes a byte to the stream at the current position.
public WriteByte ( byte value ) : void
value byte The byte to write.
Результат void