Example #1
0
        private void openOrCreateMemoryAndWriteData <T>(T data)
        {
            mutex.WaitOne();
            try
            {
                mapFile = MemoryMappedFile.Open(MapAccess.FileMapAllAccess, fileName);
            }
            catch
            {
                mapFile = MemoryMappedFile.Create(MapProtection.PageReadWrite, 8 * 1024, fileName);
            }

            Stream writer = mapFile.MapView(MapAccess.FileMapAllAccess, 0, 8 * 1024);

            char[] charArrayOfObject = serializeToXml <T>(data).ToCharArray();


            for (int i = 0; i < charArrayOfObject.Length; i++)
            {
                writer.WriteByte((byte)charArrayOfObject[i]);
            }
            writer.Flush();
            writer.Close();
            mutex.ReleaseMutex();
        }
Example #2
0
        private void readDataFromMemory()
        {
            if (mapFile == null)
            {
                try
                {
                    mapFile = MemoryMappedFile.Open(MapAccess.FileMapAllAccess, fileName);
                }
                catch
                {
                    mapFile = null;
                    throw new Exception("File " + fileName + " is not opened yet.");
                }
            }

            try
            {
                reader = mapFile.MapView(MapAccess.FileMapRead, 0, 8 * 1024);
            }
            catch (Exception)
            {
                Debug.WriteLine("Error in Reading");
            }
            getObjectFromMMF <TestData>();
        }
Example #3
0
 protected void MapView(ref long viewStartIdx, ref long viewSize)
 {
     // Now map the view
     _viewBaseAddr = _backingFile.MapView(_access, viewStartIdx, viewSize);
     _viewStartIdx = viewStartIdx;
     _viewSize     = viewSize;
 }