Esempio n. 1
0
 /// <summary>
 ///   Performs application-defined tasks associated with freeing, 
 ///   releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (!_memoryBlock.IsInvalid) {
         _memoryBlock.Dispose();
         _memoryBlock = _invalidBlock;
     }
 }
Esempio n. 2
0
        /// <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(int capacity)
        {
            var currentSize = _memoryBlock.IsInvalid ? 0 : _memoryBlock.Size;
            if (capacity > currentSize) {
                if (0 != currentSize) {
                    currentSize <<= 1;
                }
                if (capacity > currentSize) {
                    currentSize = capacity;
                }

                if (!_memoryBlock.IsInvalid) {
                    _memoryBlock.Dispose();
                }
                _memoryBlock = SafeHGlobalHandle.Allocate(currentSize);
            }
        }
Esempio n. 3
0
        /// <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(int capacity)
        {
            var currentSize = _memoryBlock.IsInvalid ? 0 : _memoryBlock.Size;

            if (capacity > currentSize)
            {
                if (0 != currentSize)
                {
                    currentSize <<= 1;
                }
                if (capacity > currentSize)
                {
                    currentSize = capacity;
                }

                if (!_memoryBlock.IsInvalid)
                {
                    _memoryBlock.Dispose();
                }
                _memoryBlock = SafeHGlobalHandle.Allocate(currentSize);
            }
        }
Esempio n. 4
0
 internal static extern bool BackupRead(SafeFileHandle hFile, SafeHGlobalHandle pBuffer, int numberOfBytesToRead, out int numberOfBytesRead,
     [MarshalAs(UnmanagedType.Bool)] bool abort, [MarshalAs(UnmanagedType.Bool)] bool processSecurity, ref IntPtr context);
Esempio n. 5
0
 internal static extern bool BackupRead(SafeFileHandle hFile, SafeHGlobalHandle pBuffer, int numberOfBytesToRead, out int numberOfBytesRead,
                                        [MarshalAs(UnmanagedType.Bool)] bool abort, [MarshalAs(UnmanagedType.Bool)] bool processSecurity, ref IntPtr context);