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


C# MemoryMappedViewAccessor.Write方法代码示例

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


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

示例1: RingBufferMemoryMap

 /// <summary>
 ///     Creates a new memory mapped ring buffer.
 /// </summary>
 /// <param name="size">The size of the ring buffer to create.</param>
 /// <param name="location">The location to store the ring buffer at.</param>
 /// <param name="name">The name of the ring buffer.</param>
 public RingBufferMemoryMap(long size, string location, string name)
 {
     _size = size;
     _isCreated = !System.IO.File.Exists(location);
     _file = MemoryMappedFile.CreateFromFile(location, FileMode.OpenOrCreate, name, size,
         MemoryMappedFileAccess.ReadWrite);
     _view = _file.CreateViewAccessor(0, size);
     if (_isCreated)
     {
         // If created write -1 to the front of the ring buffer so it will find position 0 as the end.
         _view.Write(0, -1L);
     }
     SeekToEnd();
 }
开发者ID:mrh0057,项目名称:net-data-structures,代码行数:20,代码来源:RingBufferMemoryMap.cs

示例2: Init

        private void Init()
        {
            if (!File.Exists(_fileName))
            {
                _file = MemoryMappedFile.CreateNew(_fileName, 4096);
                _accessor = _file.CreateViewAccessor();
                var begin = new Position();
                _accessor.Write(0, ref begin);
            }
            else
            {
                _file = MemoryMappedFile.CreateOrOpen(_fileName, 4096);
                _accessor = _file.CreateViewAccessor();
            }

            while (true)
            { 
                Position current;
                _accessor.Read(0, out current);

                var _lastRead = Enumerable.Empty<RecordedEvent>();

                _eventStoreConnection.ReadAllEventsForwardAsync(new ClientAPI.Position(current.Commit, current.Prepare), _batch)
                    .ContinueWith(s =>
                    {
                        Publish(s.Result.Events);

                        _lastRead = s.Result.Events;

                        int lastCount = current.Count;
                        current = new Position
                        {
                            Prepare = s.Result.Position.PreparePosition,
                            Commit = s.Result.Position.CommitPosition,
                            Count = lastCount + s.Result.Events.Count()
                        };
                        _accessor.Write(0, ref current);
                    }).Wait();

                if (_lastRead.Count() < _batch)
                    break;
            }

        }
开发者ID:valeriob,项目名称:EventStore.CommonDomain,代码行数:44,代码来源:Event_Publisher.cs

示例3: InnerResetData

		private static CacheNotifyDataMapInfo InnerResetData(MemoryMappedViewAccessor accessor)
		{
			for (int i = 0; i < GetTotalMemorySize(); i++)
				accessor.Write(i, (byte)0);

			CacheNotifyDataMapInfo mapInfo;

			accessor.Read(0, out mapInfo);

			mapInfo.Mark = CacheNotifyDataMapInfo.Tag;

			accessor.Write(0, ref mapInfo);

			return mapInfo;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:15,代码来源:CacheNotifyDataMap.cs

示例4: WriteOneCacheNotifyData

		private static void WriteOneCacheNotifyData(MemoryMappedViewAccessor accessor, ref CacheNotifyDataMapInfo mapInfo, CacheNotifyData notifyData, long currentTicks)
		{
			if (mapInfo.Pointer >= CacheNotifyDataMapInfo.CacheDataItemCount)
				mapInfo.Pointer = 0;

			long startPointer = Marshal.SizeOf(typeof(CacheNotifyDataMapInfo)) +
				mapInfo.Pointer * (Marshal.SizeOf(typeof(CacheNotifyDataMapItem)) + CacheNotifyDataMapInfo.CacheDataBlockSize);

			byte[] data = notifyData.ToBytes();

			CacheNotifyDataMapItem item = new CacheNotifyDataMapItem();

			item.Ticks = currentTicks;
			item.Size = data.Length;

			accessor.Write(startPointer, ref item);

			long dataPointer = startPointer + Marshal.SizeOf(typeof(CacheNotifyDataMapItem));

			accessor.WriteArray(dataPointer, data, 0, data.Length);

			mapInfo.Pointer++;

			accessor.Write(0, ref mapInfo);

			UdpCacheNotifier.TotalCounters.MmfSentItemsCounter.Increment();
			UdpCacheNotifier.TotalCounters.MmfSentCountPerSecond.Increment();

			UdpCacheNotifier.AppInstanceCounters.MmfSentItemsCounter.Increment();
			UdpCacheNotifier.AppInstanceCounters.MmfSentCountPerSecond.Increment();

			UdpCacheNotifier.TotalCounters.MmfCurrentPointer.RawValue = mapInfo.Pointer;
			UdpCacheNotifier.AppInstanceCounters.MmfCurrentPointer.RawValue = mapInfo.Pointer;
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:34,代码来源:CacheNotifyDataMap.cs

示例5: SendOrder

        public void SendOrder(object m_comOrder)
        {
            a_comOrder.order = ((ComOrder)m_comOrder).order;
            a_comOrder.customFuncNum = ((ComOrder)m_comOrder).customFuncNum;
            comOrderMMFViewAccessor = comOrderMMF.CreateViewAccessor(0, capacity);
            //循环写入,使在这个进程中可以向共享内存中写入不同的字符串值
            string input;
            input = XmlSerialize.SerializeXML<ComOrder>(a_comOrder);
            comOrderMMFViewAccessor.Write(0, input.Length);
            comOrderMMFViewAccessor.WriteArray<char>(4, input.ToArray(), 0, input.Length);
#if DEBUG
            Debug.WriteLine(a_comOrder.order);
#endif

        }
开发者ID:wangqipy,项目名称:GuideFuncService,代码行数:15,代码来源:Form1.cs


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