// This is a Reflection hack to workaround clr bug 6441.  
 //
 // MemoryMappedViewAccessor.SafeMemoryMappedViewHandle.AcquirePointer returns a pointer
 // that has been aligned to SYSTEM_INFO.dwAllocationGranularity.  Unfortunately the 
 // offset from this pointer to our requested offset into the MemoryMappedFile is only
 // available through the UnmanagedMemoryStream._offset field which is not exposed publicly.
 //
 private long GetPrivateOffset(MemoryMappedViewAccessor stream)
 {
     System.Reflection.FieldInfo unmanagedMemoryStreamOffset = typeof(MemoryMappedViewAccessor).GetField("m_view", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField);
     object memoryMappedView = unmanagedMemoryStreamOffset.GetValue(stream);
     System.Reflection.PropertyInfo memoryMappedViewPointerOffset = memoryMappedView.GetType().GetProperty("PointerOffset", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty);
     return (long)memoryMappedViewPointerOffset.GetValue(memoryMappedView);
 }
        //List<CVarHeader> VarHeaders = new List<CVarHeader>();

        public bool Startup()
        {
            if (IsInitialized) return true;

            try
            {
                iRacingFile = MemoryMappedFile.OpenExisting(Defines.MemMapFileName);
                FileMapView = iRacingFile.CreateViewAccessor();
                
                VarHeaderSize = Marshal.SizeOf(typeof(VarHeader));

                var hEvent = OpenEvent(Defines.DesiredAccess, false, Defines.DataValidEventName);
                var are = new AutoResetEvent(false);
                are.Handle = hEvent;

                var wh = new WaitHandle[1];
                wh[0] = are;

                WaitHandle.WaitAny(wh);

                Header = new CiRSDKHeader(FileMapView);
                GetVarHeaders();

                IsInitialized = true;
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Beispiel #3
0
        public SRHSharedData()
        {
            m_Mmf = MemoryMappedFile.CreateNew(@"SimpleROHook1008",
                Marshal.SizeOf(typeof(StSHAREDMEMORY)),
                MemoryMappedFileAccess.ReadWrite);
            if (m_Mmf == null)
                MessageBox.Show("CreateOrOpen MemoryMappedFile Failed.");
            m_Accessor = m_Mmf.CreateViewAccessor();

            byte* p = null;
            m_Accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref p);
            m_pSharedMemory = (StSHAREDMEMORY*)p;

            write_packetlog = false;
            freemouse = false;
            m2e = false;
            fix_windowmode_vsyncwait = false;
            show_framerate = false;
            objectinformation = false;
            _44khz_audiomode = false;
            cpucoolerlevel = 0;
            configfilepath = "";
            musicfilename = "";
            executeorder = false;
            g_hROWindow = 0;
        }
        public MemoryMappedFileCheckpoint(string filename, string name, bool cached, bool mustExist = false, long initValue = 0)
        {
            _filename = filename;
            _name = name;
            _cached = cached;
            var old = File.Exists(_filename);
            _fileStream = new FileStream(_filename,
                                            mustExist ? FileMode.Open : FileMode.OpenOrCreate,
                                            FileAccess.ReadWrite,
                                            FileShare.ReadWrite);
            _file = MemoryMappedFile.CreateFromFile(_fileStream,
                                                    Guid.NewGuid().ToString(),
                                                    sizeof(long),
                                                    MemoryMappedFileAccess.ReadWrite,
                                                    new MemoryMappedFileSecurity(),
                                                    HandleInheritability.None,
                                                    false);
            _accessor = _file.CreateViewAccessor(0, 8);

            if (old)
                _last = _lastFlushed = ReadCurrent();
            else
            {
                _last = initValue;
                Flush();
            }
        }
Beispiel #5
0
 public MappedBuffer(MemoryMappedViewAccessor view, int pos, int len)
 {
     this.view = view;
     this.pos = pos;
     this.len = len;
     Check.Slice(pos, len, view.Capacity);
 }
        public void Dispose()
        {
            if (_accessor != null)
                _accessor.Dispose();

            _accessor = null;
        }
 public CVarBuf(MemoryMappedViewAccessor mapView, CiRSDKHeader header)
 {
     FileMapView = mapView;
     Header = header;
     VarHeaderSize = Marshal.SizeOf(typeof(VarHeader));
     VarBufSize = Marshal.SizeOf(typeof(VarBuf));
 }
Beispiel #8
0
        void InitWriter()
        {
            string prefix = sm.instanceType == tiesky.com.SharmIpcInternals.eInstanceType.Master ? "1" : "2";

            if (ewh_Writer_ReadyToRead == null)
            {
                ewh_Writer_ReadyToRead  = new EventWaitHandle(false, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
                ewh_Writer_ReadyToWrite = new EventWaitHandle(true, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
                ewh_Writer_ReadyToWrite.Set();
            }

            //if (sm.instanceType == tiesky.com.SharmIpc.eInstanceType.Master)
            //{
            //    Console.WriteLine("My writer handlers:");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
            //    Console.WriteLine("-------");
            //}


            if (Writer_mmf == null)
            {
                Writer_mmf      = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(sm.uniqueHandlerName + prefix + "_SharmNet_MMF", sm.bufferCapacity, MemoryMappedFileAccess.ReadWrite);
                Writer_accessor = Writer_mmf.CreateViewAccessor(0, sm.bufferCapacity);
            }
        }
        public MemoryMapReader(string file)
        {
            var fileInfo = new FileInfo(file);

            Length = (int)fileInfo.Length;

            // Ideally we would use the file ID in the mapName, but it is not
            // easily available from C#.
            var mapName = $"{fileInfo.FullName.Replace("\\", "-")}-{Length}";
            lock (FileLocker)
            {
                try
                {
                    _memoryMappedFile = MemoryMappedFile.OpenExisting(mapName, MemoryMappedFileRights.Read);
                }
                catch (Exception ex) when (ex is IOException || ex is NotImplementedException)
                {
                    using (
                        var stream = new FileStream(file, FileMode.Open, FileAccess.Read,
                            FileShare.Delete | FileShare.Read))
                    {
                        _memoryMappedFile = MemoryMappedFile.CreateFromFile(stream, mapName, Length,
                            MemoryMappedFileAccess.Read, null, HandleInheritability.None, false);
                    }
                }
            }

            _view = _memoryMappedFile.CreateViewAccessor(0, Length, MemoryMappedFileAccess.Read);
        }
 void MapContent()
 {
     if (_accessor != null) return;
     _memoryMappedFile = MemoryMappedFile.CreateFromFile(_stream, null, 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.None, true);
     _accessor = _memoryMappedFile.CreateViewAccessor();
     _accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref _pointer);
 }
 public BitmapBroadcaster()
 {
     file = MemoryMappedFile.CreateOrOpen("OpenNiVirtualCamFrameData", fileSize, MemoryMappedFileAccess.ReadWrite);
     memoryAccessor = file.CreateViewAccessor(0, fileSize, MemoryMappedFileAccess.ReadWrite);
     if (hasServer())
         throw new Exception("Only one server is allowed.");
 }
        internal MemoryMappedFile(string path)
        {
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);

            _mmf  = SIOMMF.MemoryMappedFile.CreateFromFile(fs, null, 0, SIOMMF.MemoryMappedFileAccess.Read, null, HandleInheritability.None, false);
            _mmva = _mmf.CreateViewAccessor(0, 0, SIOMMF.MemoryMappedFileAccess.Read);
            _mmva.SafeMemoryMappedViewHandle.AcquirePointer(ref _ptr);
        }
        public MemoryMappedFileCommunicator(MemoryMappedFile rpMemoryMappedFile, long rpOffset, long rpSize, MemoryMappedFileAccess rpAccess)
        {
            r_MemoryMappedFile = rpMemoryMappedFile;
            r_ViewAccessor = rpMemoryMappedFile.CreateViewAccessor(rpOffset, rpSize, rpAccess);

            ReadPosition = -1;
            r_WritePosition = -1;
        }
Beispiel #14
0
 public MumbleLink()
 {
     if (mmFile == null)
     {
         mmFile = MemoryMappedFile.CreateOrOpen("MumbleLink", Marshal.SizeOf(data), MemoryMappedFileAccess.ReadWrite);
         mmAccessor = mmFile.CreateViewAccessor(0, Marshal.SizeOf(data));
     }
 }
Beispiel #15
0
 public cFileMap(FileStream stream, FileMapProtect protect, int offset, int length)
 {
     MemoryMappedFileAccess cProtect = (protect == FileMapProtect.ReadWrite) ? MemoryMappedFileAccess.ReadWrite : MemoryMappedFileAccess.Read;
     _length = length;
     _mappedFile = MemoryMappedFile.CreateFromFile(stream, stream.Name, _length, cProtect, null, HandleInheritability.None, true);
     _mappedFileAccessor = _mappedFile.CreateViewAccessor(offset, _length, cProtect);
     _addr = _mappedFileAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle();
 }
Beispiel #16
0
        public DebuggerForm()
        {
            InitializeComponent();

            m_MMF = MemoryMappedFile.CreateOrOpen( @"VoronoiDebugger", 1 << 20, MemoryMappedFileAccess.ReadWrite );
            m_View = m_MMF.CreateViewAccessor( 0, 1 << 20, MemoryMappedFileAccess.ReadWrite );	// Open in R/W even though we won't write into it, just because we need to have the same access privileges as the writer otherwise we make the writer crash when it attempts to open the file in R/W mode!

            integerTrackbarControlCell_ValueChanged( null, 0 );
        }
Beispiel #17
0
        public MappedByteBuffer(MemoryMappedFile memoryMappedFile, long offset, int length)
        {
            _memoryMappedFile = memoryMappedFile;
            byte* ptr = (byte*)0;
            _view = memoryMappedFile.CreateViewAccessor(offset, length);
            _view.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);

            Pointer = new IntPtr(ptr);
        }
 void UnmapContent()
 {
     if (_accessor == null) return;
     _accessor.SafeMemoryMappedViewHandle.ReleasePointer();
     _accessor.Dispose();
     _accessor = null;
     _memoryMappedFile.Dispose();
     _memoryMappedFile = null;
 }
Beispiel #19
0
		public void Allocate()
		{
			//we can't allocate 0 bytes here.. so just allocate 1 byte here if 0 was requested. it should be OK, and we dont have to handle cases where blocks havent been allocated
			int sizeToAlloc = Size;
			if (sizeToAlloc == 0) sizeToAlloc = 1;
			mmf = MemoryMappedFile.CreateNew(BlockName, sizeToAlloc);
			mmva = mmf.CreateViewAccessor();
			mmva.SafeMemoryMappedViewHandle.AcquirePointer(ref Ptr);
		}
Beispiel #20
0
 private void SetBlockEntry(int index)
 {
     if (BlockEntryIndex != index)
     {
         BlockEntry.Dispose();
         BlockEntry = File.CreateViewAccessor(
             BlockEntryOffset + (BlockEntrySize * index), BlockEntrySize, MemoryMappedFileAccess.Read);
     }
 }
Beispiel #21
0
        internal unsafe MemoryMappedFileBlock(MemoryMappedViewAccessor accessor)
        {
            byte* ptr = null;
            accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
            ptr += GetPrivateOffset(accessor);

            this.accessor = accessor;
            this.pointer = (IntPtr)ptr;
        }
            public MemoryMappedInfo(string name, long size)
            {
                _name = name;
                _size = size;

                _memoryMappedFile = MemoryMappedFile.OpenExisting(_name);

                _streamCount = 0;
                _accessor = null;
            }
        public RTSSController(string appId)
        {
            _mmf = MemoryMappedFile.OpenExisting("RTSSSharedMemoryV2");
            _view = _mmf.CreateViewAccessor();
            _appId = appId;

            Refresh();

            ValidateUniqueAppId();
        }
Beispiel #24
0
        public StreamHeaderRef(MemoryMappedViewAccessor accessor)
        {
            Accessor = accessor;
            Buffer = accessor.GetSafeBuffer();

            byte* temp = null;
            Buffer.AcquirePointer(ref temp);

            Ptr = (StreamHeader*)temp;
        }
Beispiel #25
0
        public MemoryMappedReadWriteContext(MemoryMappedViewAccessor viewAccessor,
            MemoryMappedViewStream viewStream, Mutex accessMutex, bool lockOnCreate)
        {
            ViewAccessor = viewAccessor;
            ViewStream = viewStream;
            _accessMutex = accessMutex;

            if (lockOnCreate)
                Lock();
        }
            public MemoryMappedInfo(long size)
            {
                _name = CreateUniqueName(size);
                _size = size;

                _memoryMappedFile = MemoryMappedFile.CreateNew(_name, size);

                _streamCount = 0;
                _accessor = null;
            }
 public MemoryMappedFileMessageSender(string name)
 {
     _file = MemoryMappedFile.CreateOrOpen(name, SizeOfFile);
     _bytesWrittenAccessor = _file.CreateViewAccessor(0, SizeOfInt32);
     _messageCompletedAccessor = _file.CreateViewAccessor(SizeOfInt32, SizeOfBool);
     _stream = _file.CreateViewStream(SizeOfInt32 + SizeOfBool + SizeOfBool, SizeOfStream);
     _messageSendingEvent = new EventWaitHandle(false, EventResetMode.AutoReset, name + "_MessageSending");
     _messageReadEvent = new EventWaitHandle(false, EventResetMode.AutoReset, name + "_MessageRead");
     _messageCancelledEvent = new EventWaitHandle(false, EventResetMode.ManualReset, name + "_MessageCancelled");
     _bytesWrittenEvent = new EventWaitHandle(false, EventResetMode.AutoReset, name + "_BytesWritten");
     _bytesReadEvent = new EventWaitHandle(false, EventResetMode.AutoReset, name + "_BytesRead");
 }
        private void MapFile(long capacity)
        {
            if (Pointer != IntPtr.Zero)
                return;

            _file = MemoryMappedFile.CreateFromFile(Address, FileMode.Open, null, capacity, MemoryMappedFileAccess.ReadWrite);
            _accessor = _file.CreateViewAccessor();
            byte* pointer = null;
            _accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);

            Pointer = new IntPtr(pointer);
        }
        public MemoryMappedFileCommunicator(MemoryMappedFile mappedFile, long offset, long size, MemoryMappedFileAccess access)
        {
            MappedFile = mappedFile;
            view = mappedFile.CreateViewAccessor(offset, size, access);

            ReadPosition = -1;
            writePosition = -1;
            dataToSend = new List<byte[]>();

            callback = new SendOrPostCallback(OnDataReceivedInternal);
            operation = AsyncOperationManager.CreateOperation(null);
        }
Beispiel #30
0
 public BDFEDFAccessor(BDFEDFFileStream.BDFEDFFileStream bdf)
 {
     isBDF = bdf.header.isBDFFile;
     recordLength = bdf.NumberOfSamples(0) * (isBDF ? 3 : 2);
     recordSetLength = recordLength * bdf.NumberOfChannels;
     long size = (long)bdf.NumberOfRecords * recordSetLength;
     MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(bdf.baseStream, "MMF",
         size + bdf.header.headerSize, MemoryMappedFileAccess.ReadWrite, null,
         System.IO.HandleInheritability.Inheritable, false);
     _BDFEDFHeader = bdf.header;
     MemoryMappedFileSecurity mmfs = new MemoryMappedFileSecurity();
     accessor = mmf.CreateViewAccessor(bdf.header.headerSize, size);
 }
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (_disposed)
     {
         throw new ObjectDisposedException("Memory mapped file");
     }
     _ptr = null;
     _mmva.Dispose();
     _mmva = null;
     _mmf.Dispose();
     _mmf      = null;
     _disposed = true;
 }
Beispiel #32
0
        public static unsafe void ReadBytes(MemoryMappedViewAccessor view, long offset, ref long[] arr)
        {
            //byte[] arr = new byte[num];
            var ptr = (byte*)0;

            view.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
            var ip = new IntPtr(ptr);
            var iplong = ip.ToInt64() + offset;
            var ptr_off = new IntPtr(iplong);

            Marshal.Copy(ptr_off, arr, 0, 512);
            view.SafeMemoryMappedViewHandle.ReleasePointer();
        }
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (_disposed)
     {
         throw new ObjectDisposedException("Memory mapped file");
     }
     _ptr = null;
     _mmva.SafeMemoryMappedViewHandle.ReleasePointer();
     _mmva.Dispose();
     _mmva = null;
     _mmf.Dispose();
     _mmf      = null;
     _disposed = true;
 }
Beispiel #34
0
        /// <summary>
        ///
        /// </summary>
        void InitReader()
        {
            string prefix = sm.instanceType == eInstanceType.Slave ? "1" : "2";

            if (ewh_Reader_ReadyToRead == null)
            {
                ewh_Reader_ReadyToRead  = new EventWaitHandle(false, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
                ewh_Reader_ReadyToWrite = new EventWaitHandle(true, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
                ewh_Reader_ReadyToWrite.Set();
            }

            //if (sm.instanceType == tiesky.com.SharmIpc.eInstanceType.Slave)
            //{
            //    Console.WriteLine("My reader handlers:");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
            //    Console.WriteLine("-------");
            //}


            if (Reader_mmf == null)
            {
                Reader_mmf      = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(sm.uniqueHandlerName + prefix + "_SharmNet_MMF", sm.bufferCapacity, MemoryMappedFileAccess.ReadWrite);
                Reader_accessor = Reader_mmf.CreateViewAccessor(0, sm.bufferCapacity);
            }

            Task.Run(() =>
            {
                byte[] hdr           = null;
                byte[] ret           = null;
                ushort iCurChunk     = 0;
                ushort iTotChunk     = 0;
                ulong iMsgId         = 0;
                int iPayLoadLen      = 0;
                ulong iResponseMsgId = 0;

                eMsgType msgType = eMsgType.RpcRequest;

                try
                {
                    while (true)
                    {
                        ewh_Reader_ReadyToRead.WaitOne();
                        if (ewh_Reader_ReadyToRead == null) //Special Dispose case
                        {
                            return;
                        }
                        ewh_Reader_ReadyToRead.Reset();
                        //Reading data from MMF

                        //Reading header
                        hdr     = ReadBytes(0, protocolLen);
                        msgType = (eMsgType)hdr[0];

                        //Parsing header
                        switch (msgType)
                        {
                        case eMsgType.ErrorInRpc:

                            iPayLoadLen    = BitConverter.ToInt32(hdr, 9);   //+4
                            iResponseMsgId = BitConverter.ToUInt64(hdr, 17); //+8

                            DataArrived(msgType, iResponseMsgId, null);
                            break;

                        case eMsgType.RpcResponse:
                        case eMsgType.RpcRequest:
                        case eMsgType.Request:

                            bool zeroByte = false;
                            iMsgId        = BitConverter.ToUInt64(hdr, 1); //+8
                            iPayLoadLen   = BitConverter.ToInt32(hdr, 9);  //+4
                            if (iPayLoadLen == Int32.MaxValue)
                            {
                                zeroByte    = true;
                                iPayLoadLen = 0;
                            }
                            iCurChunk      = BitConverter.ToUInt16(hdr, 13); //+2
                            iTotChunk      = BitConverter.ToUInt16(hdr, 15); //+2
                            iResponseMsgId = BitConverter.ToUInt64(hdr, 17); //+8

                            if (iCurChunk == 1)
                            {
                                chunksCollected = null;
                                MsgId_Received  = iMsgId;
                            }
                            else if (iCurChunk != currentChunk + 1)
                            {
                                //Wrong income, sending special signal back, waiting for new MsgId
                                switch (msgType)
                                {
                                case eMsgType.RpcRequest:
                                    this.SendMessage(eMsgType.ErrorInRpc, this.GetMessageId(), null, iMsgId);
                                    break;

                                case eMsgType.RpcResponse:
                                    DataArrived(eMsgType.ErrorInRpc, iResponseMsgId, null);
                                    break;
                                }
                                break;
                            }

                            if (iTotChunk == iCurChunk)
                            {
                                if (chunksCollected == null)
                                {
                                    DataArrived(msgType, (msgType == eMsgType.RpcResponse) ? iResponseMsgId : iMsgId, iPayLoadLen == 0 ? ((zeroByte) ? new byte[0] : null) : ReadBytes(protocolLen, iPayLoadLen));
                                }
                                else
                                {
                                    ret = new byte[iPayLoadLen + chunksCollected.Length];
                                    Buffer.BlockCopy(chunksCollected, 0, ret, 0, chunksCollected.Length);
                                    Buffer.BlockCopy(ReadBytes(protocolLen, iPayLoadLen), 0, ret, chunksCollected.Length, iPayLoadLen);
                                    DataArrived(msgType, (msgType == eMsgType.RpcResponse) ? iResponseMsgId : iMsgId, ret);
                                }
                                chunksCollected = null;
                                currentChunk    = 0;
                            }
                            else
                            {
                                if (chunksCollected == null)
                                {
                                    chunksCollected = ReadBytes(protocolLen, iPayLoadLen);
                                }
                                else
                                {
                                    byte[] tmp = new byte[chunksCollected.Length + iPayLoadLen];
                                    Buffer.BlockCopy(chunksCollected, 0, tmp, 0, chunksCollected.Length);
                                    Buffer.BlockCopy(ReadBytes(protocolLen, iPayLoadLen), 0, tmp, chunksCollected.Length, iPayLoadLen);
                                    chunksCollected = tmp;
                                }

                                currentChunk = iCurChunk;
                            }
                            break;

                        default:
                            //Unknown protocol type
                            chunksCollected = null;
                            currentChunk    = 0;
                            //Wrong income, doing nothing
                            throw new Exception("tiesky.com.SharmIpc: Reading protocol contains errors");
                            //break;
                        }

                        //Setting signal
                        ewh_Reader_ReadyToWrite.Set();
                    }
                }
                catch
                {}
            });
        }
Beispiel #35
0
        public void Dispose()
        {
            try
            {
                if (ewh_Writer_ReadyToRead != null)
                {
                    //ewh_Writer_ReadyToRead.Set();
                    ewh_Writer_ReadyToRead.Close();
                    ewh_Writer_ReadyToRead.Dispose();
                    ewh_Writer_ReadyToRead = null;
                }
            }
            catch
            {
            }
            try
            {
                if (ewh_Writer_ReadyToWrite != null)
                {
                    //ewh_Writer_ReadyToWrite.Set();
                    ewh_Writer_ReadyToWrite.Close();
                    ewh_Writer_ReadyToWrite.Dispose();
                    ewh_Writer_ReadyToWrite = null;
                }
            }
            catch
            {
            }

            try
            {
                if (ewh_Reader_ReadyToRead != null)
                {
                    //ewh_Reader_ReadyToRead.Set();
                    ewh_Reader_ReadyToRead.Close();
                    ewh_Reader_ReadyToRead.Dispose();
                    ewh_Reader_ReadyToRead = null;
                }
            }
            catch
            {
            }
            try
            {
                if (ewh_Reader_ReadyToWrite != null)
                {
                    //ewh_Reader_ReadyToWrite.Set();
                    ewh_Reader_ReadyToWrite.Close();
                    ewh_Reader_ReadyToWrite.Dispose();
                    ewh_Reader_ReadyToWrite = null;
                }
            }
            catch
            {}

            try
            {
                if (Writer_accessor != null)
                {
                    Writer_accessor.Dispose();
                    Writer_accessor = null;
                }
            }
            catch
            {}
            try
            {
                if (Reader_accessor != null)
                {
                    Reader_accessor.Dispose();
                    Reader_accessor = null;
                }
            }
            catch
            { }
            try
            {
                if (Writer_mmf != null)
                {
                    Writer_mmf.Dispose();
                    Writer_mmf = null;
                }
            }
            catch
            { }
            try
            {
                if (Reader_mmf != null)
                {
                    Reader_mmf.Dispose();
                    Reader_mmf = null;
                }
            }
            catch
            { }
        }
 internal MemoryMappedFile(string path)
 {
     _mmf  = SIOMMF.MemoryMappedFile.CreateFromFile(path);
     _mmva = _mmf.CreateViewAccessor();
     _mmva.SafeMemoryMappedViewHandle.AcquirePointer(ref _ptr);
 }
        public SharedMemory(string name, IntPtr size)
        {
            mmf = MemoryMappedFile.OpenExisting(name + "_CONNECT_DATA");

            mmva = mmf.CreateViewAccessor();
            if (mmf.SafeMemoryMappedFileHandle.IsInvalid)
                throw new MySqlException("Cannot open file mapping " + name);
            mmvs = mmf.CreateViewStream(0L, size.ToInt64());
            mmva = mmf.CreateViewAccessor(0L, size.ToInt64());
        }