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
Afficher le fichier Open project: aleksk/LazyCopy Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void

Releases unmanaged and - optionally - managed resources.

Private Methods

Méthode 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 méthode

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
Résultat System.IntPtr

Dispose() public méthode

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

Dispose() protected méthode

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. ///
Résultat void

ResizableBuffer() public méthode

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

ResizableBuffer() public méthode

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.
Résultat System

Resize() public méthode

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.
Résultat void