C# Class BF2Statistics.Net.BufferManager

This class creates a single large buffer which can be divided up and assigned to SocketAsyncEventArgs objects for use with each socket I/O operation. This enables buffers to be easily reused and guards against fragmenting heap memory.
Inheritance: IDisposable
Show file Open project: BF2Statistics/ControlCenter Class Usage Examples

Public Properties

Property Type Description
BytesToAllocPerEventArg int

Protected Properties

Property Type Description
Buffer byte[]
FreeBufferSpace ConcurrentStack

Public Methods

Method Description
AssignBuffer ( SocketAsyncEventArgs args ) : bool

Assigns a buffer space from the buffer block to the specified SocketAsyncEventArgs object.

BufferManager ( int NumEventArgs, int BytesToAllocPerEventArg ) : System

Creates a new instance of BufferManager

Dispose ( ) : void

Releases all bytes held by this buffer

ReleaseBuffer ( SocketAsyncEventArgs args ) : void

Releases Buffer space assigned to a token so that it can be assingned to a new SAEA

Private Methods

Method Description
CheckDisposed ( ) : void

If Dispose() has been called on this object, an ObjectDisposedException will be thrown here

Method Details

AssignBuffer() public method

Assigns a buffer space from the buffer block to the specified SocketAsyncEventArgs object.
public AssignBuffer ( SocketAsyncEventArgs args ) : bool
args System.Net.Sockets.SocketAsyncEventArgs The SocketEventArgs object to assign a buffer space to
return bool

BufferManager() public method

Creates a new instance of BufferManager
public BufferManager ( int NumEventArgs, int BytesToAllocPerEventArg ) : System
NumEventArgs int Specifies the maximum number of SocketAsyncEventArgs objects that will be assigned buffer space at once
BytesToAllocPerEventArg int Specifies the number of bytes each SocketAsyncEventArgs object will be allocated from the buffer
return System

Dispose() public method

Releases all bytes held by this buffer
public Dispose ( ) : void
return void

ReleaseBuffer() public method

Releases Buffer space assigned to a token so that it can be assingned to a new SAEA
public ReleaseBuffer ( SocketAsyncEventArgs args ) : void
args System.Net.Sockets.SocketAsyncEventArgs The SocketEventArgs object that we are releasing buffer space from
return void

Property Details

Buffer protected property

Our buffer object
protected byte[] Buffer
return byte[]

BytesToAllocPerEventArg public property

The number of bytes each SocketAsyncEventArgs object gets allocated inside the Buffer for all IO operations
public int BytesToAllocPerEventArg
return int

FreeBufferSpace protected property

Contains free buffer space, which can be assigned to new SAEA
protected ConcurrentStack FreeBufferSpace
return ConcurrentStack