C# Класс 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.
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
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.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void

Releases unmanaged and - optionally - managed resources.

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

Метод Описание
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.

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

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

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
Результат System.IntPtr

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

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

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. ///
Результат void

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

Initializes a new instance of the ResizableBuffer class.
The Environment.SystemPageSize is passed as an initial size.
Buffer was not allocated.
public ResizableBuffer ( ) : System
Результат System

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

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.
Результат System

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

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.
Результат void