/// <summary> /// Ensures that there is sufficient memory allocated. /// </summary> /// <param name="capacity"> /// The required capacity of the block, in bytes. /// </param> /// <exception cref="OutOfMemoryException"> /// There is insufficient memory to satisfy the request. /// </exception> public void EnsureCapacity(Int32 capacity) { Int32 currentSize = MemoryBlock.IsInvalid ? 0 : MemoryBlock.Size; if (currentSize >= capacity) { return; } if (currentSize != 0) { currentSize <<= 1; } if (currentSize < capacity) { currentSize = capacity; } if (!MemoryBlock.IsInvalid) { MemoryBlock.Dispose(); } MemoryBlock = SafeGlobalHandle.Allocate(currentSize); }
/// <summary> /// Performs application-defined tasks associated with freeing, /// releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (MemoryBlock.IsInvalid) { return; } MemoryBlock.Dispose(); MemoryBlock = InvalidBlock; }