Example #1
0
        void FreeMemoryMappedIoData()
        {
            if (dataAry == null)
            {
                var origData = Interlocked.Exchange(ref data, IntPtr.Zero);
                if (origData != IntPtr.Zero)
                {
                    dataLength = 0;
                    switch (osType)
                    {
                    case OSType.Windows:
                        Windows.Dispose(origData);
                        break;

                    case OSType.Unix:
                        Unix.Dispose(origData, origDataLength);
                        break;

                    default:
                        throw new InvalidOperationException("Shouldn't be here");
                    }
                }
            }

            if (gcHandle.IsAllocated)
            {
                try {
                    gcHandle.Free();
                }
                catch (InvalidOperationException) {
                }
            }
            dataAry = null;
        }
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            var origData = Interlocked.Exchange(ref data, IntPtr.Zero);

            if (origData != IntPtr.Zero)
            {
                dataLength = 0;
                switch (osType)
                {
                case OSType.Windows:
                    Windows.Dispose(origData);
                    break;

                case OSType.Unix:
                    Unix.Dispose(origData, origDataLength);
                    break;

                default:
                    throw new InvalidOperationException("Shouldn't be here");
                }
            }
            base.Dispose(disposing);
        }