public void Dispose()
        {
            Disposed = true;
            GC.SuppressFinalize(this);
            if (_readHandle != null)
            {
                _readHandle.Close();
            }
            _handle.Close();
            if (_nativeOverlapped != null)
            {
                Marshal.FreeHGlobal((IntPtr)_nativeOverlapped);
                _nativeOverlapped = null;
            }
            if (_segments != null)
            {
                Marshal.FreeHGlobal((IntPtr)_segments);
                _segments = null;
            }

            if (DeleteOnClose)
            {
                try
                {
                    File.Delete(_filename);
                }
                catch (Exception)
                {
                    // if we can't delete, nothing that we can do here.
                }
            }
        }
        private void EnsureSegmentsSize(IntPtr[] pages)
        {
            if (_segmentsSize >= pages.Length + 1)
            {
                return;
            }

            _segmentsSize = (int)Utils.NearestPowerOfTwo(pages.Length + 1);

            if (_segments != null)
            {
                Marshal.FreeHGlobal((IntPtr)_segments);
            }

            _segments = (Win32NativeFileMethods.FileSegmentElement *)(Marshal.AllocHGlobal(_segmentsSize * sizeof(Win32NativeFileMethods.FileSegmentElement)));
        }
        private int EnsureSegmentsSize(IntPtr[] pages)
        {
            int physicalPages = (pages.Length * _pageSizeMultiplier);

            if (_segmentsSize >= physicalPages + 1)
            {
                return(physicalPages);
            }

            _segmentsSize = Bits.NextPowerOf2(physicalPages + 1);

            if (_segments != null)
            {
                Marshal.FreeHGlobal((IntPtr)_segments);
            }

            _segments = (Win32NativeFileMethods.FileSegmentElement *)(Marshal.AllocHGlobal(_segmentsSize * sizeof(Win32NativeFileMethods.FileSegmentElement)));
            return(physicalPages);
        }
Example #4
0
        public void Dispose()
        {
            Disposed = true;
            GC.SuppressFinalize(this);
            if (_readHandle != null)
                _readHandle.Close();
            _handle.Close();
            if (_nativeOverlapped != null)
            {
                Marshal.FreeHGlobal((IntPtr) _nativeOverlapped);
                _nativeOverlapped = null;
            }
            if (_segments != null)
            {
                Marshal.FreeHGlobal((IntPtr) _segments);
                _segments = null;
            }

            if (DeleteOnClose)
            {
                try
                {
                    File.Delete(_filename);
                }
                catch (Exception)
                {
                    // if we can't delete, nothing that we can do here.
                }
            }
        }
Example #5
0
        private void EnsureSegmentsSize(IntPtr[] pages)
        {
            if (_segmentsSize >= pages.Length + 1)
                return;

            _segmentsSize = (int) Utils.NearestPowerOfTwo(pages.Length + 1);

            if (_segments != null)
                Marshal.FreeHGlobal((IntPtr) _segments);

            _segments = (Win32NativeFileMethods.FileSegmentElement*) (Marshal.AllocHGlobal(_segmentsSize*sizeof (Win32NativeFileMethods.FileSegmentElement)));
        }