C# Class ServiceStack.Text.RecyclableMemoryStreamManager

Manages pools of RecyclableMemoryStream objects.
There are two pools managed in here. The small pool contains same-sized buffers that are handed to streams as they write more data. For scenarios that need to call GetBuffer(), the large pool contains buffers of various sizes, all multiples of LargeBufferMultiple (1 MB by default). They are split by size to avoid overly-wasteful buffer usage. There should be far fewer 8 MB buffers than 1 MB buffers, for example.
Exibir arquivo Open project: ServiceStack/ServiceStack.Text Class Usage Examples

Public Methods

Method Description
GetStream ( ) : MemoryStream

Retrieve a new MemoryStream object with no tag and a default initial capacity.

GetStream ( string tag ) : MemoryStream

Retrieve a new MemoryStream object with the given tag and a default initial capacity.

GetStream ( string tag, byte buffer, int offset, int count ) : MemoryStream

Retrieve a new MemoryStream object with the given tag and with contents copied from the provided buffer. The provided buffer is not wrapped or used after construction.

The new stream's position is set to the beginning of the stream when returned.

GetStream ( string tag, int requiredSize ) : MemoryStream

Retrieve a new MemoryStream object with the given tag and at least the given capacity.

GetStream ( string tag, int requiredSize, bool asContiguousBuffer ) : MemoryStream

Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using a single continugous underlying buffer.

Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations where the initial size is known and it is desirable to avoid copying data between the smaller underlying buffers to a single large one. This is most helpful when you know that you will always call GetBuffer on the underlying stream.

RecyclableMemoryStreamManager ( ) : System

Initializes the memory manager with the default block/buffer specifications.

RecyclableMemoryStreamManager ( int blockSize, int largeBufferMultiple, int maximumBufferSize ) : System

Initializes the memory manager with the given block requiredSize.

Private Methods

Method Description
GetBlock ( ) : byte[]

Removes and returns a single block from the pool.

GetLargeBuffer ( int requiredSize, string tag ) : byte[]

Returns a buffer of arbitrary size from the large buffer pool. This buffer will be at least the requiredSize and always be a multiple of largeBufferMultiple.

IsLargeBufferMultiple ( int value ) : bool
ReportStreamCreated ( ) : void
ReportStreamDisposed ( ) : void
ReportStreamFinalized ( ) : void
ReportStreamLength ( long bytes ) : void
ReportStreamToArray ( ) : void
ReturnBlocks ( ICollection blocks, string tag ) : void

Returns the blocks to the pool

ReturnLargeBuffer ( byte buffer, string tag ) : void

Returns the buffer to the large pool

RoundToLargeBufferMultiple ( int requiredSize ) : int

Method Details

GetStream() public method

Retrieve a new MemoryStream object with no tag and a default initial capacity.
public GetStream ( ) : MemoryStream
return System.IO.MemoryStream

GetStream() public method

Retrieve a new MemoryStream object with the given tag and a default initial capacity.
public GetStream ( string tag ) : MemoryStream
tag string A tag which can be used to track the source of the stream.
return System.IO.MemoryStream

GetStream() public method

Retrieve a new MemoryStream object with the given tag and with contents copied from the provided buffer. The provided buffer is not wrapped or used after construction.
The new stream's position is set to the beginning of the stream when returned.
public GetStream ( string tag, byte buffer, int offset, int count ) : MemoryStream
tag string A tag which can be used to track the source of the stream.
buffer byte The byte buffer to copy data from.
offset int The offset from the start of the buffer to copy from.
count int The number of bytes to copy from the buffer.
return System.IO.MemoryStream

GetStream() public method

Retrieve a new MemoryStream object with the given tag and at least the given capacity.
public GetStream ( string tag, int requiredSize ) : MemoryStream
tag string A tag which can be used to track the source of the stream.
requiredSize int The minimum desired capacity for the stream.
return System.IO.MemoryStream

GetStream() public method

Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using a single continugous underlying buffer.
Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations where the initial size is known and it is desirable to avoid copying data between the smaller underlying buffers to a single large one. This is most helpful when you know that you will always call GetBuffer on the underlying stream.
public GetStream ( string tag, int requiredSize, bool asContiguousBuffer ) : MemoryStream
tag string A tag which can be used to track the source of the stream.
requiredSize int The minimum desired capacity for the stream.
asContiguousBuffer bool Whether to attempt to use a single contiguous buffer.
return System.IO.MemoryStream

RecyclableMemoryStreamManager() public method

Initializes the memory manager with the default block/buffer specifications.
public RecyclableMemoryStreamManager ( ) : System
return System

RecyclableMemoryStreamManager() public method

Initializes the memory manager with the given block requiredSize.
blockSize is not a positive number, or largeBufferMultiple is not a positive number, or maximumBufferSize is less than blockSize. maximumBufferSize is not a multiple of largeBufferMultiple
public RecyclableMemoryStreamManager ( int blockSize, int largeBufferMultiple, int maximumBufferSize ) : System
blockSize int Size of each block that is pooled. Must be > 0.
largeBufferMultiple int Each large buffer will be a multiple of this value.
maximumBufferSize int Buffers larger than this are not pooled
return System