当前位置: 首页>>代码示例>>C#>>正文


C# MemoryMappedFile.Dispose方法代码示例

本文整理汇总了C#中System.IO.MemoryMappedFiles.MemoryMappedFile.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryMappedFile.Dispose方法的具体用法?C# MemoryMappedFile.Dispose怎么用?C# MemoryMappedFile.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryMappedFiles.MemoryMappedFile的用法示例。


在下文中一共展示了MemoryMappedFile.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FileSegment

 public FileSegment(MemoryMappedFile mmf, long offset, long length, MemoryMappedFileAccess access)
 {
     _mmf = Exceptions.CheckArgumentNull(mmf, "mmf");
     try
     {
         _length = length;
         if (_length == 0)
             _stream = new MemoryStream();
         else
             _stream = mmf.CreateViewStream(offset, length, access);
     }
     catch
     {
         _mmf.Dispose();
         throw;
     }
 }
开发者ID:kidaa,项目名称:Pulse,代码行数:17,代码来源:FileSegment.cs

示例2: IsConnected

        public bool IsConnected()
        {
            if (Accessor != null)
                return true;

            var dataValidEvent = Event.OpenEvent(Event.EVENT_ALL_ACCESS | Event.EVENT_MODIFY_STATE, false, "Local\\IRSDKDataValidEvent");
            if (dataValidEvent == IntPtr.Zero)
            {
                var lastError = Marshal.GetLastWin32Error();
                if (lastError == Event.ERROR_FILE_NOT_FOUND)
                    return false;

                Trace.WriteLine(string.Format("Unable to open event Local\\IRSDKDataValidEvent - Error Code {0}", lastError), "DEBUG");
                return false;
            }

            MemoryMappedFile irsdkMappedMemory = null;
            try
            {
                irsdkMappedMemory = MemoryMappedFile.OpenExisting("Local\\IRSDKMemMapFileName");
            }
            catch (Exception e)
            {
                Trace.WriteLine("Error accessing shared memory", "DEBUG");
                Trace.WriteLine(e.Message, "DEBUG");
            }

            if (irsdkMappedMemory == null)
                return false;

            var accessor = irsdkMappedMemory.CreateViewAccessor();
            if (accessor == null)
            {
                irsdkMappedMemory.Dispose();
                Trace.WriteLine("Unable to Create View into shared memory", "DEBUG");
                return false;
            }

            this.irsdkMappedMemory = irsdkMappedMemory;
            this.dataValidEvent = dataValidEvent;
            Accessor = accessor;
            return true;
        }
开发者ID:RobRobertsCE,项目名称:iRacingSolution,代码行数:43,代码来源:iRacingMemory.cs

示例3: DumpFileMemoryReader

        public DumpFileMemoryReader(string dumpFilePath)
        {
            bool dispose = true;
            FileStream fileStream = null;
            MemoryMappedFile memoryMappedFile = null;
            MemoryMappedViewStream stream = null;

            try
            {
                fileStream = new FileStream(dumpFilePath, FileMode.Open, FileAccess.Read);
                memoryMappedFile = MemoryMappedFile.CreateFromFile(fileStream, Guid.NewGuid().ToString(), fileStream.Length, MemoryMappedFileAccess.Read, new MemoryMappedFileSecurity(), HandleInheritability.Inheritable, false);
                stream = memoryMappedFile.CreateViewStream(0, fileStream.Length, MemoryMappedFileAccess.Read);

                stream.SafeMemoryMappedViewHandle.AcquirePointer(ref basePointer);
                IntPtr streamPointer = IntPtr.Zero;
                uint streamSize = 0;
                MINIDUMP_DIRECTORY directory = new MINIDUMP_DIRECTORY();

                if (!MiniDumpReadDumpStream((IntPtr)basePointer, MINIDUMP_STREAM_TYPE.Memory64ListStream, ref directory, ref streamPointer, ref streamSize))
                    throw new Exception("Unable to read mini dump stream");

                var data = (MINIDUMP_MEMORY64_LIST)Marshal.PtrToStructure(streamPointer, typeof(MINIDUMP_MEMORY64_LIST));
                ulong lastEnd = data.BaseRva;

                ranges = new MemoryLocation[data.NumberOfMemoryRanges];
                for (int i = 0; i < ranges.Length; i++)
                {
                    var descriptor = (MINIDUMP_MEMORY_DESCRIPTOR64)Marshal.PtrToStructure(streamPointer + sizeof(MINIDUMP_MEMORY64_LIST) + i * sizeof(MINIDUMP_MEMORY_DESCRIPTOR64), typeof(MINIDUMP_MEMORY_DESCRIPTOR64));
                    ranges[i] = new MemoryLocation()
                    {
                        MemoryStart = descriptor.StartOfMemoryRange,
                        MemoryEnd = descriptor.StartOfMemoryRange + descriptor.DataSize,
                        FilePosition = lastEnd,
                    };
                    lastEnd += descriptor.DataSize;
                }

                int newEnd = 0;
                for (int i = 1; i < ranges.Length; i++)
                    if (ranges[i].MemoryStart == ranges[newEnd].MemoryEnd)
                        ranges[newEnd].MemoryEnd = ranges[i].MemoryEnd;
                    else
                        ranges[++newEnd] = ranges[i];
                newEnd++;
                Array.Resize(ref ranges, newEnd);
                finder = new MemoryRegionFinder(ranges.Select(r => new MemoryRegion { BaseAddress = r.MemoryStart, MemoryEnd = r.MemoryEnd }).ToArray());
                dispose = false;
            }
            finally
            {
                if (dispose)
                {
                    stream.SafeMemoryMappedViewHandle.ReleasePointer();
                    if (stream != null)
                    {
                        stream.Dispose();
                    }

                    if (memoryMappedFile != null)
                    {
                        memoryMappedFile.Dispose();
                    }

                    if (fileStream != null)
                    {
                        fileStream.Dispose();
                    }
                }
                else
                {
                    this.fileStream = fileStream;
                    this.stream = stream;
                    this.memoryMappedFile = memoryMappedFile;
                }
            }
        }
开发者ID:southpolenator,项目名称:WinDbgCs,代码行数:76,代码来源:DumpFileMemoryReader.cs

示例4: read_events_thread

        private void read_events_thread() {

            string prefix = use_global_ ? "Global\\" : "";
            try {
                memory_file_ = MemoryMappedFile.CreateNew(prefix + "DBWIN_BUFFER", 4096L);

                bool created = false;
                buffer_ready_ = new EventWaitHandle( false, EventResetMode.AutoReset, prefix + "DBWIN_BUFFER_READY", out created);
                if (!created) 
                    errors_.add("Can't create the DBWIN_BUFFER_READY event/" + use_global_);

                if (created) {
                    data_ready_ = new EventWaitHandle(false, EventResetMode.AutoReset, prefix + "DBWIN_DATA_READY", out created);
                    if (!created) 
                        errors_.add("Can't create the DBWIN_DATA_READY event/" + use_global_);
                }

                if (created) {
                    buffer_ready_.Set();
                    while (!disposed_) {
                        if (!data_ready_.WaitOne(1000))
                            continue;

                        using (var stream = memory_file_.CreateViewStream()) {
                            using (var reader = new BinaryReader(stream, Encoding.Default)) {
                                var process_id = (int)reader.ReadUInt32();
                                var raw = reader.ReadChars(4092);
                                var idx = Array.IndexOf(raw, '\0');
                                var msg = new string(raw, 0, idx);
                                find_process_id(process_id);
                                string process_name = pid_to_name_.ContainsKey(process_id) ? pid_to_name_[process_id] : "";
                                lock (this)
                                    events_.Add(new debug_event {
                                        unique_id = next_unique_id++, process_id = process_id, msg = msg, lo_process_name = process_name
                                    });
                            }
                        }
                
                        buffer_ready_.Set();
                    }
                }
            } catch (Exception e) {
                logger.Fatal("Can't read debug events " + e.Message);
                errors_.add("Error reading debug events " + e.Message);
            }

            if ( memory_file_ != null)
                memory_file_.Dispose();
            if ( data_ready_ != null)
                data_ready_.Dispose();
            if ( buffer_ready_ != null)
                buffer_ready_.Dispose();

        }
开发者ID:CaulyKan,项目名称:logwizard,代码行数:54,代码来源:capture_all_debug_events.cs

示例5: InitFromStream

 private void InitFromStream(Stream input, uint length)
 {
     m_map = MemoryMappedFile.CreateNew (null, length, MemoryMappedFileAccess.ReadWrite,
         MemoryMappedFileOptions.None, null, HandleInheritability.None);
     try
     {
         using (var view = m_map.CreateViewAccessor (0, length, MemoryMappedFileAccess.Write))
         {
             var buffer = new byte[81920];
             unsafe
             {
                 byte* ptr = view.GetPointer (0);
                 try
                 {
                     uint total = 0;
                     while (total < length)
                     {
                         int read = input.Read (buffer, 0, buffer.Length);
                         if (0 == read)
                             break;
                         read = (int)Math.Min (read, length-total);
                         Marshal.Copy (buffer, 0, (IntPtr)(ptr+total), read);
                         total += (uint)read;
                     }
                     MaxOffset = total;
                 }
                 finally
                 {
                     view.SafeMemoryMappedViewHandle.ReleasePointer();
                 }
             }
         }
         View = new Frame (this);
     }
     catch
     {
         m_map.Dispose();
         throw;
     }
 }
开发者ID:Casidi,项目名称:GARbro,代码行数:40,代码来源:ArcView.cs

示例6: InitFromFileStream

 private void InitFromFileStream(FileStream fs, uint length)
 {
     m_map = MemoryMappedFile.CreateFromFile (fs, null, length,
         MemoryMappedFileAccess.Read, null, HandleInheritability.None, true);
     try {
         View = new Frame (this);
     } catch {
         m_map.Dispose(); // dispose on error only
         throw;
     }
 }
开发者ID:Casidi,项目名称:GARbro,代码行数:11,代码来源:ArcView.cs

示例7: MemoryMappedIndexInput

        public MemoryMappedIndexInput(string file)
        {
            this._length = new FileInfo(file).Length;

            _mmf = MemoryMappedFile.CreateFromFile(file, FileMode.Open);
            try
            {
                _accessor = _mmf.CreateViewAccessor(0, _length);
            }
            catch (IOException ex)
            {
                _mmf.Dispose();
                throw ex;
            }
        }
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:15,代码来源:MemoryMappedDirectory.cs


注:本文中的System.IO.MemoryMappedFiles.MemoryMappedFile.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。