public unsafe void WriteChars_VeryLargeArray_DoesNotOverflow()
        {
            const nuint INT32_OVERFLOW_SIZE = (nuint)int.MaxValue + 3;

            SafeBuffer unmanagedBuffer = null;

            try
            {
                try
                {
                    unmanagedBuffer = SafeBufferUtil.CreateSafeBuffer(INT32_OVERFLOW_SIZE * sizeof(byte));
                }
                catch (OutOfMemoryException)
                {
                    throw new SkipTestException($"Unable to execute {nameof(WriteChars_VeryLargeArray_DoesNotOverflow)} due to OOM"); // skip test in low-mem conditions
                }

                Assert.True((long)unmanagedBuffer.ByteLength > int.MaxValue);

                // reuse same memory for input and output to avoid allocating more memory and OOMs
                Span <char> span = new Span <char>((char *)unmanagedBuffer.DangerousGetHandle(), (int)(INT32_OVERFLOW_SIZE / sizeof(char)));
                span.Fill('\u0224'); // LATIN CAPITAL LETTER Z WITH HOOK
                Stream       outStream = new UnmanagedMemoryStream(unmanagedBuffer, 0, (long)unmanagedBuffer.ByteLength, FileAccess.ReadWrite);
                BinaryWriter writer    = new BinaryWriter(outStream);

                writer.Write(span); // will write slightly more than int.MaxValue bytes to the output

                Assert.Equal((long)INT32_OVERFLOW_SIZE, outStream.Position);
            }
            finally
            {
                unmanagedBuffer?.Dispose();
            }
        }
예제 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (buffer != null)
     {
         if (disposing)
         {
             buffer.Dispose();
         }
     }
     buffer = null;
 }
예제 #3
0
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _buffer?.Dispose();
                    _accessor?.Dispose();
                    _file?.Dispose();
                }
                disposedValue = true;
            }
        }
예제 #4
0
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;
            ScratchBuffer.Dispose();
            UploadBuffer.Dispose();

            lock (Lock)
                ReleaseBindings();
        }
        private bool disposedValue = false; // To detect redundant calls

        private void Dispose(bool disposing)
        {
            if (!disposedValue && !_properties.IsClosed)
            {
                disposedValue = true;

                if (_providers.Count > 0)
                {
                    foreach (var prov in _providers)
                    {
                        Guid provider_id = prov.ProviderId;
                        Win32NativeMethods.EnableTraceEx2(_handle, ref provider_id,
                                                          EventControlCode.DisableProvider, prov.Level, 0, 0, 0, null);
                    }
                }

                Win32NativeMethods.ControlTrace(_handle, null,
                                                _properties, EventTraceControl.Stop);
                _properties?.Dispose();
            }
        }
예제 #6
0
 public override void Dispose()
 {
     mBuffer.Dispose();
     mViewAcessor.Dispose();
     mFile.Dispose();
 }