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


C# MemoryMappedFile.CreateViewStream方法代码示例

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


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

示例1: 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

示例2: 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

示例3: HeurFacade

 public HeurFacade(string mutName, string mmfName, int RegIterations)
 {
     // Time of listening before register
     this.Luogo1 = new Dictionary<string, Network>();
     this.threshold = RegIterations;
     this.mut = Mutex.OpenExisting(mutName); ;
     this.mmf = MemoryMappedFile.OpenExisting(mmfName, MemoryMappedFileRights.FullControl, HandleInheritability.None);
     this.stream = mmf.CreateViewStream(0, MappedFileDimension, MemoryMappedFileAccess.Read);
 }
开发者ID:palexster,项目名称:ermesReloaded,代码行数:9,代码来源:HeurFacade.cs

示例4: MappedFileBuffer

        public MappedFileBuffer(byte[] data)
        {
            _file = MemoryMappedFile.CreateNew(Guid.NewGuid().ToString(), data.Length);
            _stream = _file.CreateViewStream();
            _stream.Write(data, 0, data.Length);
            
			//File.WriteAllBytes(_file.Name, data);
			_size = (uint)data.Length;
		}
开发者ID:dremerdt,项目名称:fo-dicom,代码行数:9,代码来源:MappedFileBuffer.cs

示例5: SharedRingBuffer

 public SharedRingBuffer(string name, int size)
 {
     _size = size;
     _memory = MemoryMappedFile.CreateOrOpen(name, size + 1);
     _memoryStream = _memory.CreateViewStream();
     _writer = new BinaryWriter(_memoryStream);
     _reader = new BinaryReader(_memoryStream);
     _writer.Write(char.MinValue);
 }
开发者ID:Moones,项目名称:OpenEnsage,代码行数:9,代码来源:SharedRingBuffer.cs

示例6: SharedMemory

        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());
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:10,代码来源:SharedMemoryStream.cs

示例7: MemoryMappedFileMessageSender

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

示例8: Write

 /// <summary>
 /// 非持久化内存映射文件写入
 /// </summary>
 /// <param name="name"></param>
 /// <param name="capacity"></param>
 /// <param name="en"></param>
 /// <param name="buffer"></param>
 public void Write(string name, Int64 capacity, Encoding en, byte[] buffer)
 {
     using (mmf = MemoryMappedFile.CreateNew(name, capacity, MemoryMappedFileAccess.ReadWrite))
     {
         using (MemoryMappedViewStream mmvs = mmf.CreateViewStream())
         {
             using (BinaryWriter bw = new BinaryWriter(mmvs, en))
             {
                 bw.Write(buffer);
             }
         }
     }
 }
开发者ID:zhangwuhua,项目名称:ZwhAid4.0,代码行数:20,代码来源:MemoryFileAid.cs

示例9: FileReader

        /// <summary>
        /// Creates a new FileReader instance.
        /// </summary>
        /// <param name="Path">The path of the file to read.</param>
        /// <param name="BigEndian">Is the filed stored as big endian?</param>
        public FileReader(string Path, bool BigEndian)
        {
            m_MemFile = MemoryMappedFile.CreateFromFile(Path, FileMode.Open, Guid.NewGuid().ToString(), 0,
                MemoryMappedFileAccess.Read);

            try
            {
                m_Reader = new BinaryReader(m_MemFile.CreateViewStream(0, 0, MemoryMappedFileAccess.Read));
            }
            catch(IOException Exception)
            {
                throw new ReadingException("Couldn't open file - FileReader.cs\r\n" + Exception.ToString());
            }
        }
开发者ID:Afr0Games,项目名称:Project-Dollhouse,代码行数:19,代码来源:FileReader.cs

示例10: Read

 /// <summary>
 /// 内存映射文件读取
 /// </summary>
 /// <param name="name">内存映射文件名称</param>
 /// <param name="capacity">内存映射文件大小</param>
 /// <param name="en">编码</param>
 public byte[] Read(string name, Int64 capacity, Encoding en)
 {
     byte[] buffer = new byte[capacity];
     using (mmf = MemoryMappedFile.OpenExisting(name))
     {
         using (MemoryMappedViewStream mmvs = mmf.CreateViewStream())
         {
             using (BinaryReader br = new BinaryReader(mmvs, en))
             {
                 int length = int.Parse(capacity.ToString());
                 br.Read(buffer, 0, length);
             }
         }
     }
     return buffer;
 }
开发者ID:zhangwuhua,项目名称:ZwhAid4.0,代码行数:22,代码来源:MemoryFileAid.cs

示例11: 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

示例12: ConnectImpl

        public ConnectImpl()
        {
            _onDataUpdatedEvent = new EventWaitHandle(true, EventResetMode.ManualReset, OnDataUpdatedEventName);
            _onWriteLockMutex = new Mutex(false, OnWriteLockMutexName);

            using (GetLock())
            {
                try
                {
                    _memoryMappedFile = MemoryMappedFile.OpenExisting(MemoryMappedFileName);
                }
                catch (FileNotFoundException)
                {
                    _memoryMappedFile = MemoryMappedFile.CreateNew(MemoryMappedFileName, MemoryMappedFileSize);
                }

                _memoryMappedViewAccessor = _memoryMappedFile.CreateViewAccessor();
                _memoryMappedViewStream = _memoryMappedFile.CreateViewStream();
                _memoryMappedViewHandle = _memoryMappedViewStream.SafeMemoryMappedViewHandle.DangerousGetHandle();
            }
        }
开发者ID:roman-rudenko,项目名称:MultiCurrencyTester,代码行数:21,代码来源:ConnectImpl.cs

示例13: ParityChange

 public ParityChange(Parity parity, Config config, UInt32 startBlock, UInt32 lengthInBlocks)
 {
     this.parity = parity;
       this.startBlock = startBlock;
       tempDir = config.TempDir;
       writingToMMF = true;
       UInt32 maxMMFBlocks = Parity.LengthInBlocks((long)config.MaxTempRAM * 1024 * 1024);
       UInt32 mmfBlocks = (lengthInBlocks < maxMMFBlocks) ? lengthInBlocks : maxMMFBlocks;
       try {
     mmf = MemoryMappedFile.CreateNew("disparity.tmp", (long)mmfBlocks * Parity.BLOCK_SIZE);
     mmfStream = mmf.CreateViewStream();
       }
       catch (Exception e) {
     LogFile.Log("Could not create memory mapped file: " + e.Message);
     // We'll use a temp file only
     mmf = null;
     mmfStream = null;
     writingToMMF = false;
       }
       tempFileStream = null;
       parityBlock = new ParityBlock(parity);
       block = startBlock;
 }
开发者ID:codeicon,项目名称:disParity,代码行数:23,代码来源:ParityChange.cs

示例14: CreateServer

        /// <summary>
        /// </summary>
        /// <returns></returns>
        public bool CreateServer()
        {
            try
            {
                _memoryMappedFile = MemoryMappedFile.CreateOrOpen(_smKeyStoreName, _smKeyStoreSize);
                _reader = _memoryMappedFile.CreateViewAccessor(0, _smKeyStoreSize, MemoryMappedFileAccess.ReadWrite);
                _writer = _memoryMappedFile.CreateViewStream(0, _smKeyStoreSize, MemoryMappedFileAccess.ReadWrite);
                _keystoreLock = new Mutex(true, LageantLock, out _isLocked);
            }
            catch
            {
                return false;
            }

            return true;
        }
开发者ID:bitbeans,项目名称:lageant,代码行数:19,代码来源:LageantCore.cs

示例15: CopyNextChunkAsync

        /// <summary>
        /// The copy next chunk async.
        /// </summary>
        /// <param name="memoryMappedFile">
        /// The memory mapped file.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        /// <exception cref="DownloadAcceleratorException">
        /// Thrown if the web server returns the wrong amount of data.
        /// </exception>
        private async Task<Status> CopyNextChunkAsync(MemoryMappedFile memoryMappedFile)
        {
            HttpWebRequest httpWebRequest = this.GetWebRequest();
            long chunkId;
            lock (this.stateLock)
            {
                if (this.chunkPosition == this.numberOfChunks)
                {
                    return Status.Complete;
                }

                chunkId = this.chunkPosition++;
            }

            long offset = chunkId * this.chunkSize;
            long length = Math.Min(this.chunkSize, this.Size - offset);
            httpWebRequest.AddRange(offset, offset + length - 1);

            using (WebResponse webResponse = await httpWebRequest.GetResponseAsync())
            {
                if (long.Parse(webResponse.Headers[HttpResponseHeader.ContentLength]) != length)
                {
                    throw new DownloadAcceleratorException("Server returned incorrect amount of data");
                }

                using (MemoryMappedViewStream memoryMappedViewStream = memoryMappedFile.CreateViewStream(offset, length))
                {
                    await this.CopyToWithProgressAsync(webResponse.GetResponseStream(), memoryMappedViewStream);
                }
            }

            return Status.Incomplete;
        }
开发者ID:nmalaguti,项目名称:Maxel,代码行数:45,代码来源:DownloadAccelerator.cs


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