C# Class LazyCopy.Utilities.ResizableBuffer

This class maintains its own internal buffer and extends it, if the it is too small to fit the desired data.
The main reason of using this class is to avoid unnecessary memory allocations.
For example, the same memory can be used for getting the driver notification and then storing the reply message into, so there's no need to allocate two separate memory blocks.
Inheritance: IDisposable
显示文件 Open project: aleksk/LazyCopy Class Usage Examples

Public Methods

Method Description
DangerousGetPointer ( ) : IntPtr

Gets the pointer to the internal buffer.

Be careful with the pointer returned, because it may become invalid after the next Resize function call and after the ResizableBuffer instance is disposed.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

ResizableBuffer ( ) : System

Initializes a new instance of the ResizableBuffer class.

The Environment.SystemPageSize is passed as an initial size.

ResizableBuffer ( int initialSize ) : System

Initializes a new instance of the ResizableBuffer class.

Resize ( int newSize ) : void

Resizes the buffer.

Be careful with the pointer returned, because it may become invalid after the next Resize function call and after the ResizableBuffer instance is disposed.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases unmanaged and - optionally - managed resources.

Private Methods

Method Description
EnsureBufferIsOfTheRightSize ( int newSize ) : void

Ensures that the current buffer can store the newSize bytes. If the current buffer is not large enough, it's extended.

Method Details

DangerousGetPointer() public method

Gets the pointer to the internal buffer.
Be careful with the pointer returned, because it may become invalid after the next Resize function call and after the ResizableBuffer instance is disposed.
Buffer is already disposed.
public DangerousGetPointer ( ) : IntPtr
return System.IntPtr

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void

Dispose() protected method

Releases unmanaged and - optionally - managed resources.
protected Dispose ( bool disposing ) : void
disposing bool /// to release both managed and unmanaged resources; to release only unmanaged resources. ///
return void

ResizableBuffer() public method

Initializes a new instance of the ResizableBuffer class.
The Environment.SystemPageSize is passed as an initial size.
Buffer was not allocated.
public ResizableBuffer ( ) : System
return System

ResizableBuffer() public method

Initializes a new instance of the ResizableBuffer class.
is lesser or equal to zero or greater than the maximum size allowed. Buffer was not allocated.
public ResizableBuffer ( int initialSize ) : System
initialSize int Initial buffer size.
return System

Resize() public method

Resizes the buffer.
Be careful with the pointer returned, because it may become invalid after the next Resize function call and after the ResizableBuffer instance is disposed.
Buffer is already disposed. is lesser or equal to zero or greater than the maximum size allowed.
public Resize ( int newSize ) : void
newSize int The desired buffer size.
return void