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


C# MemoryMappedFiles.MemoryMappedFile类代码示例

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


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

示例1: Startup

        //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;
        }
开发者ID:mochablendy,项目名称:iRacingSdkWrapper,代码行数:33,代码来源:iRacingSDK.cs

示例2: MainWindow

 public MainWindow()
 {
     InitializeComponent();
     videoSource = new WriteableBitmap(640, 480, 72, 72, PixelFormats.Rgb24, null);
     rectifiedTabletopMmf = MemoryMappedFile.OpenExisting("InteractiveSpaceRectifiedTabletop", MemoryMappedFileRights.Read);
     buffer = new byte[imgSize];
 }
开发者ID:UCSD-HCI,项目名称:RiskBoardGame,代码行数:7,代码来源:MainWindow.xaml.cs

示例3: SRHSharedData

        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;
        }
开发者ID:Jasty777,项目名称:SimpleROHook,代码行数:26,代码来源:SRHSharedData.cs

示例4: MemoryMapReader

        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);
        }
开发者ID:RalphSim,项目名称:MaxMind-DB-Reader-dotnet,代码行数:29,代码来源:MemoryMapReader.cs

示例5: GetFileNameOfMemoryMappedFile

        public static string GetFileNameOfMemoryMappedFile(MemoryMappedFile file)
        {
            const uint size = 522;
            IntPtr path = Marshal.AllocCoTaskMem(unchecked((int)size)); // MAX_PATH + 1 char

            string result = null;
            try
            {
                // constant 0x2 = VOLUME_NAME_NT
                uint test = GetFinalPathNameByHandle(file.SafeMemoryMappedFileHandle.DangerousGetHandle(), path, size, 0x2);
                if (test != 0)
                    throw new Win32Exception();

                result = Marshal.PtrToStringAuto(path);
            }
            catch
            {
                uint test = GetMappedFileName(Process.GetCurrentProcess().Handle, file.SafeMemoryMappedFileHandle.DangerousGetHandle(), path, size);
                if (test != 0)
                    throw new Win32Exception();

                result = Marshal.PtrToStringAuto(path);
            }

            return result;
        }
开发者ID:robpaveza,项目名称:stormlibsharp,代码行数:26,代码来源:Win32Methods.cs

示例6: BitmapBroadcaster

 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.");
 }
开发者ID:pasinduc,项目名称:NiVirtualCam,代码行数:7,代码来源:BitmapBroadcaster.cs

示例7: FileHardDisk

        public FileHardDisk(string path)
        {
            var fi = new FileInfo(path);
            mSize = fi.Length;

            mFile = MemoryMappedFile.CreateFromFile(path, FileMode.Open);
        }
开发者ID:AustinWise,项目名称:ZfsSharp,代码行数:7,代码来源:FileHardDisk.cs

示例8: MemoryMappedFileCheckpoint

        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();
            }
        }
开发者ID:rcknight,项目名称:AppDotNetEvents,代码行数:27,代码来源:MemoryMappedFileCheckpoint.cs

示例9: Allocate

		/// <summary>
		/// note that a few bytes of the size will be used for a management area
		/// </summary>
		/// <param name="size"></param>
		public void Allocate(int size)
		{
			Owner = true;
			Id = SuperGloballyUniqueID.Next();
			mmf = MemoryMappedFile.CreateNew(Id, size);
			Setup(size);
		}
开发者ID:ddugovic,项目名称:RASuite,代码行数:11,代码来源:IPCRingBuffer.cs

示例10: InitSharedMemory

        private void InitSharedMemory()
        {
            _messageMemoryMappedFile = MemoryMappedFile.CreateOrOpen(@"messageMemory", 1024*1024, MemoryMappedFileAccess.ReadWrite);

            _collisionFlagMemoryMappedFile = MemoryMappedFile.CreateOrOpen(@"collisionFlag", 8, MemoryMappedFileAccess.ReadWrite);
            SetCollision(false);
        }
开发者ID:drodov,项目名称:VKSiS,代码行数:7,代码来源:MainWindow.xaml.cs

示例11: IncreaseSize

        public Stream IncreaseSize(int value, out long offset)
        {
            lock (_lock)
            {
                while (Interlocked.Read(ref _counter) != 0)
                {
                    if (!Monitor.Wait(_lock, 10000, true))
                        throw new NotSupportedException();
                }

                FileStream file = new FileStream(_filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                try
                {
                    offset = MathEx.RoundUp(file.Length, 0x800);
                    file.SetLength(offset + value);
                    _mmf = MemoryMappedFile.CreateFromFile(file, null, 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, false);
                }
                catch
                {
                    file.SafeDispose();
                    throw;
                }

                Interlocked.Increment(ref _counter);
                DisposableStream result = new DisposableStream(_mmf.CreateViewStream(offset, value, MemoryMappedFileAccess.ReadWrite));
                result.AfterDispose.Add(new DisposableAction(Free));
                return result;
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:29,代码来源:SharedMemoryMappedFile.cs

示例12: Complex4Ks

 public Complex4Ks(long complexEntryCount)
 {
     Debug.Assert(complexEntryCount > fourK);
     Debug.Assert(complexEntryCount % 0x1000 == 0);
     Debug.Assert((complexEntryCount != 0) && ((complexEntryCount & (complexEntryCount - 1)) == 0), "complexEntryCount must be power of 2");
     this.length4ks = complexEntryCount / fourK;
     Debug.Assert(complexEntryCount == fourK * this.length4ks);
     bool ramIsLow = this.length4ks > 1024;
     if (!ramIsLow)
     {
         lock (totalRAMLock)
         {
             ramIsLow = totalRAM <= 0L;
         }
     }
     if (ramIsLow)
     {
         lock (nameSuffixLock)
         {
             this.suffix = nameSuffix++;
         }
         this.file = MemoryMappedFile.CreateFromFile(FileName, FileMode.CreateNew, namePrefix + "-" + suffix, complexEntryCount * 16L, MemoryMappedFileAccess.ReadWrite);
     }
     else
     {
         lock (totalRAMLock)
         {
             totalRAM -= this.length4ks * 4096 * 16;
         }
         this.array = new Complex[this.length4ks][];
     }
 }
开发者ID:khwas,项目名称:gigafft,代码行数:32,代码来源:ComplexStream.cs

示例13: MapContent

 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);
 }
开发者ID:mano-cz,项目名称:BTDB,代码行数:7,代码来源:OnDiskMemoryMappedFileCollection.cs

示例14: MumbleLink

 public MumbleLink()
 {
     if (mmFile == null)
     {
         mmFile = MemoryMappedFile.CreateOrOpen("MumbleLink", Marshal.SizeOf(data), MemoryMappedFileAccess.ReadWrite);
         mmAccessor = mmFile.CreateViewAccessor(0, Marshal.SizeOf(data));
     }
 }
开发者ID:Danmashel,项目名称:Gw2MappingLink,代码行数:8,代码来源:MumbleLink.cs

示例15: CreateFileStreams

		private void CreateFileStreams()
		{
			if (_file != null || _fileStream != null)
				throw new InvalidOperationException();

			_file = MemoryMappedFile.CreateFromFile(FileName);
			_fileStream = _file.CreateViewStream();
		}
开发者ID:ethanmoffat,项目名称:PELoaderLib,代码行数:8,代码来源:PEFile.cs


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