Show / Hide Table of Contents

Class PooledMemoryStream

Creates a stream whose backing store is memory. Instances of this type are kept in a pool for recycling.

Inheritance
System.Object
PooledMemoryStream
Implements
IFreeable
IClearable
Namespace: System.IO
Assembly: Nuqleon.Memory.dll
Syntax
public class PooledMemoryStream : MemoryStream, IFreeable, IClearable

Methods

Clear()

Clears the object.

Declaration
public void Clear()

Free()

Frees the object and returns it to the pool.

Declaration
public void Free()

GetBuffer()

Gets the buffer with the contents of the memory stream. Users should be careful not to use the returned buffer beyond the point of returning the pooled memory stream back to the pool.

Declaration
public byte[] GetBuffer()
Returns
Type Description
System.Byte[]

Byte array with the contents of the memory stream.

GetBufferAndFree(Action<Byte[]>)

Exposes the buffer with the contents of the memory stream and returns the memory stream back to the pool.

Declaration
public void GetBufferAndFree(Action<byte[]> processBuffer)
Parameters
Type Name Description
System.Action<System.Byte[]> processBuffer

Delegate to process the buffer. Once the delegate invocation returns, the buffer should no longer be accessed.

GetInstance()

Gets a System.IO.MemoryStream instance from the global memory stream pool.

Declaration
public static PooledMemoryStream GetInstance()
Returns
Type Description
PooledMemoryStream

A System.IO.MemoryStream instance obtained from the global pool.

New()

Gets a pooled System.IO.MemoryStream instance, from the global pool, with RAII capabilities to return it to the pool.

Declaration
public static PooledMemoryStreamHolder New()
Returns
Type Description
PooledMemoryStreamHolder

Pooled memory stream instance.

New(MemoryStreamPool)

Gets a pooled System.IO.MemoryStream instance, from the specified pool, with RAII capabilities to return it to the pool.

Declaration
public static PooledMemoryStreamHolder New(MemoryStreamPool pool)
Parameters
Type Name Description
MemoryStreamPool pool

Pool to allocate from.

Returns
Type Description
PooledMemoryStreamHolder

Pooled memory stream instance.

Exceptions
Type Condition
System.NullReferenceException

Thrown if pool is null.

ToArray()

Gets a copy of the contents of the memory stream. Note that this method does not return the memory stream back to the pool. Consider using ToArrayAndFree() to copy the contents of the memory stream to an array and return the memory stream to the pool.

Declaration
public byte[] ToArray()
Returns
Type Description
System.Byte[]

Byte array with a copy of the contents of the memory stream.

ToArrayAndFree()

Gets a copy of the contents of the memory stream and returns the memory stream back to the pool.

Declaration
public byte[] ToArrayAndFree()
Returns
Type Description
System.Byte[]

Byte array with a copy of the contents of the memory stream.

Implements

IFreeable
IClearable
In This Article
Back to top Generated by DocFX