/// <summary> /// /// </summary> /// <returns></returns> public CacheNotifyDataMapInfo Clone() { CacheNotifyDataMapInfo result = new CacheNotifyDataMapInfo(); result.Mark = this.Mark; result.Pointer = this.Pointer; return(result); }
/// <summary> /// /// </summary> /// <returns></returns> public CacheNotifyDataMapInfo Clone() { CacheNotifyDataMapInfo result = new CacheNotifyDataMapInfo(); result.Mark = this.Mark; result.Pointer = this.Pointer; return result; }
/// <summary> /// 返回Memory Mapped中的Cache通知信息的头信息 /// </summary> /// <returns></returns> public static CacheNotifyDataMapInfo GetCacheNotifyDataMapInfo() { CacheNotifyDataMapInfo result = (CacheNotifyDataMapInfo)DoAccessor(FileMode.Open, accessor => { CacheNotifyDataMapInfo mapInfo; accessor.Read(0, out mapInfo); return(mapInfo.Clone()); }); return(result); }
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; }
private static long InnerReadCacheNotifyData(long lastTicks, MemoryMappedViewAccessor accessor, CacheNotifyDataMapInfo mapInfo, List<CacheNotifyData> result) { int itemSize = Marshal.SizeOf(typeof(CacheNotifyDataMapItem)); long returnTicks = lastTicks; long startPointer = Marshal.SizeOf(typeof(CacheNotifyDataMapInfo)); for (int i = 0; i < CacheNotifyDataMapInfo.CacheDataItemCount; i++) { CacheNotifyDataMapItem item; accessor.Read(startPointer, out item); if (item.Ticks > lastTicks) { if (item.Ticks > returnTicks) returnTicks = item.Ticks; byte[] data = new byte[item.Size]; accessor.ReadArray(startPointer + itemSize, data, 0, (int)item.Size); CacheNotifyData cnd = CacheNotifyData.FromBuffer(data); result.Add(cnd); } startPointer += itemSize + CacheNotifyDataMapInfo.CacheDataBlockSize; } return returnTicks; }
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; }
private static long InnerReadCacheNotifyData(long lastTicks, MemoryMappedViewAccessor accessor, CacheNotifyDataMapInfo mapInfo, List <CacheNotifyData> result) { int itemSize = Marshal.SizeOf(typeof(CacheNotifyDataMapItem)); long returnTicks = lastTicks; long startPointer = Marshal.SizeOf(typeof(CacheNotifyDataMapInfo)); for (int i = 0; i < CacheNotifyDataMapInfo.CacheDataItemCount; i++) { CacheNotifyDataMapItem item; accessor.Read(startPointer, out item); if (item.Ticks > lastTicks) { if (item.Ticks > returnTicks) { returnTicks = item.Ticks; } byte[] data = new byte[item.Size]; accessor.ReadArray(startPointer + itemSize, data, 0, (int)item.Size); CacheNotifyData cnd = CacheNotifyData.FromBuffer(data); result.Add(cnd); } startPointer += itemSize + CacheNotifyDataMapInfo.CacheDataBlockSize; } return(returnTicks); }